%% Import All Data Using PostgreSQL Native Interface
% Import all product data from a PostgreSQL database table into MATLAB® using the PostgreSQL native interface and the fetch function. Then, determine the highest unit cost among products in the table.
%
% Create a PostgreSQL native interface database connection to a PostgreSQL database using a data source, user name, and password. The database contains the table productTable.

datasource = "PostgreSQLDataSource";
username = "dbdev";
password = "matlab";
conn = postgresql(datasource,username,password);

%
% Import all the data from productTable by using the connection object and SQL query. Then, display the first three rows of the imported data.

sqlquery = "SELECT * FROM productTable";
data = fetch(conn,sqlquery);
head(data,3)

%
% Determine the highest unit cost for all products in the table.

max(data.unitcost)

%
% Close the database connection.

close(conn)

% Copyright 2020 The MathWorks, Inc.