How to pull data and write data to a PostgreSQL database?
11 views (last 30 days)
Show older comments
Hello,
I need some help, I am trying to connect to my postgres database and use that data within my code. I made a successful connection through the "Database Explorer" app, and I can connect and get info about the contents of the database. For instance I can use an sqlfind command to look up a table and the information relating to that table, but when I try to use sqlread or sqlwrite I get errors relating to my JDBC driver.
Database = database(Databasename,username,password); %The Database connects
A = sqlfind(Database, "ISE_TEAM_LABOR_DATA") %This line works and gives me an output. The result it shown below
B = sqlread(Database, "ISE_TEAM_LABOR_DATA", 'Schema', A.Schema{1}) %This is where the code errors out. I've tried a lot of variations of this, but cant seem to get it

Here is the driver information:
Database and Driver Information:
DatabaseProductName: 'PostgreSQL'
DatabaseProductVersion: '11.9'
DriverName: 'PostgreSQL JDBC Driver'
DriverVersion: '42.2.19'
4 Comments
Tim Darrah
on 26 Aug 2021
If you are just trying to return the table data, try using fetch or select and see what happens. I have two open questions regarding the database toolbox and postgres, sqlwrite is erroring for me (although its a datatype conversion issue with Matlab's implementation).
data = select(Database, 'select * from CAP_FILES;')
It's interesting that the ODBC driver uses select, while the postgres native driver uses fetch (I have not used JDBC).
data = fetch(Database, 'select * from CAP_FILES;')
prabhat kumar sharma
on 24 Jul 2024
I guess it's the capitalization issue. what capitalization schema is using should be passed to the sqlread.
Can you check the table name and capitalization using sqlread and use the same capitalization.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!