Main Content

PostgreSQL ODBC for macOS DSN-Less Connection

This tutorial shows how to connect to a PostgreSQL database using a DSN-less connection string at the MATLAB® command line on the Apple macOS platform. A DSN-less connection string enables you to make a connection to the database without specifying a data source name (DSN). This tutorial uses the PostgreSQL ODBC driver that comes with MATLAB.

To connect to the database, use the DSN-less connection string and the shipped PostgreSQL ODBC driver with the odbc function. This example assumes that you are connecting to a database server dbtb10, the port number is 5432, toy_store is the database name, dbdev is the username, matlab is the password, and driverLocation is the location of the ODBC driver.

driverLocation = fullfile(matlabroot,"bin","maci64","psqlodbcw.so")
dsnless = strcat("Driver=",driverLocation,";Server=dbtb10;Port=5432;UID=dbdev;PWD=matlab;Database=toy_store")
conn = odbc(dsnless)

See Also

Functions

Related Topics