How to pull data and write data to a PostgreSQL database?

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 件のコメント

Geoff Hayes
Geoff Hayes 2021 年 8 月 26 日
Tim - does the schema make sense? The error message is indicating that the software doesn't like the ampersand & character. Looking at schema the value presented here seems suspect. (To be honest, I don't really know what this should represent).
Tim Starbuck
Tim Starbuck 2021 年 8 月 26 日
I was really hoping that it was going to be that ampersand becasue both of the schema that I was pulling from contained it, but I just tried switching to pulling a table which didnt contain a special character in either the table name or the schema, and got a similar error.
Here is what I adjusted the code to. The Schema for this one is titled "Cost Data".
Databasename = 'ISEBusinessOps';
username = 'usename';
password = '*********';
BusOps_Database = database(Databasename,username,password)
tablename = "CAP_FILES"
A = sqlfind(BusOps_Database, tablename)
B = sqlread(BusOps_Database, tablename)
It produces this error:
Tim Darrah
Tim Darrah 2021 年 8 月 26 日
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
prabhat kumar sharma 2024 年 7 月 24 日
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.

サインインしてコメントする。

回答 (0 件)

製品

リリース

R2020b

質問済み:

2021 年 8 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by