%% Import Data from Database Table Using PostgreSQL Native Interface
% Use a PostgreSQL native interface database connection to import product data from a database table into MATLAB® using a PostgreSQL database. Then, perform a simple data analysis.
%
% Create a PostgreSQL native interface database connection to a PostgreSQL database. The database contains the table productTable.

datasource = "PostgreSQLDataSource";
username = "dbdev";
password = "matlab";

conn = postgresql(datasource,username,password);

%
% Import data from the database table productTable. The sqlread function returns a MATLAB table that contains the product data.

tablename = "productTable";
data = sqlread(conn,tablename);

% Display the first few rows of product data.

head(data,3)

%
% Close the database connection.

close(conn)

% Copyright 2020 The MathWorks, Inc.