Connect to a PostgreSQL database using the PostgreSQL native interface and verify the database connection. Then, import data from the database into MATLAB® using the database table productTable
. Determine the highest unit cost among the retrieved products in the table. Close the database connection and ensure that the connection is closed.
Create a PostgreSQL native interface database connection using a data source, user name, and password. The PostgreSQL database contains the table productTable
.
Determine if the database connection is open. The isopen
function returns the logical 1
, which means the database connection is open.
Select all the data from productTable
and sort it by the product number. data
is a table containing the imported data that results from executing the SQL SELECT
statement.
Display the first three rows of data.
ans=3×5 table
productnumber stocknumber suppliernumber unitcost productdescription
_____________ ___________ ______________ ________ __________________
1 4.0035e+05 1001 14 "Building Blocks"
2 4.0031e+05 1002 9 "Painting Set"
3 4.01e+05 1009 17 "Slinky"
Determine the highest unit cost in the table.
Close the database connection.
Determine if the database connection is closed. The isopen
function returns the logical 0
, which means the database connection is closed. If the database connection is invalid, the isopen
function returns the same result.