close
Close PostgreSQL native interface database connection
Syntax
Description
Examples
Create a PostgreSQL native interface connection to a PostgreSQL database. Then, import data from the database into MATLAB® and perform simple data analysis. Close the database connection.
This example assumes that you are connecting to a PostgreSQL database version 9.405 using the libpq driver version 10.12.
Connect to the database using the data source name, user name, and password.
datasource = "PostgreSQLDataSource"; username = "dbdev"; password = "matlab"; conn = postgresql(datasource,username,password)
conn =
connection with properties:
DataSource: "PostgreSQLDataSource"
UserName: "dbdev"
Database Properties:
AutoCommit: "on"
LoginTimeout: 0
MaxDatabaseConnections: 100
Catalog and Schema Information:
DefaultCatalog: "toystore_doc"
Catalogs: "toystore_doc"
Schemas: ["pg_toast", "pg_temp_1", "pg_toast_temp_1" ... and 3 more]
Database and Driver Information:
DatabaseProductName: "PostgreSQL"
DatabaseProductVersion: "9.405"
DriverName: "libpq"
DriverVersion: "10.12"
The property sections of the connection object are:
Database Properties— Information about the database configurationCatalog and Schema Information— Names of catalogs and schemas in the databaseDatabase and Driver Information— Names and versions of the database and driver
Import all data from the table inventoryTable into MATLAB using the sqlread function. Display the first three rows of data.
tablename = "inventoryTable";
data = sqlread(conn,tablename);
head(data,3)ans=3×4 table
productnumber quantity price inventorydate
_____________ ________ _____ _____________________
1 1700 14.5 "2014-09-23 09:38:34"
2 1200 9 "2014-07-08 22:50:45"
3 356 17 "2014-05-14 07:14:28"
Determine the highest product quantity from the table.
max(data.quantity)
ans = 9000
Close the database connection conn.
close(conn)
Input Arguments
PostgreSQL native interface database connection, specified as a connection object.
Version History
Introduced in R2020b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)