When writing in an already existing table - JDBC driver error relation already exists

4 ビュー (過去 30 日間)
Hi,
I'm trying to insert information obtained and modified from a .csv file to a database through matlab in order to run some tests on the public data.
To this objective I created a Postgresql database and the required table, since from this I got the idea I could pass the table from the matlab workspace onto the database table directly. I setup de JDBC connection, tested and all is okay.
However when I run the sqlwrite command, though it can create new table with the information I give, if table already exists but is empty, it simply gives the error:
Error using database.jdbc.connection/sqlwrite (line 104)
JDBC JDBC/ODBC Error: JDBC Driver Error: ERROR: relation
"ozonezurich.testschema.ozonetable" already exists.
The code,
filename = 'test.csv';
Table = Read_csv(filename);
datasource = "zurichtest";
username = "postgres";
password = "************";
conn = database(datasource,username,password);
ColumnNames = {'ObsDate','TimeStamp','Latitude','Longitude','HDOP', ...
'DeviceID','O3ppB','Temperature','Humidity'};
Table.Properties.VariableNames = ColumnNames;
sqlwrite(conn,'"ozonezurich.testschema.ozonetable"',Table(1:100,:))
close(conn);
Does anyone know how can I fix this?
P.S: Having the .csv file I know I can run the tests, however, further ahead on the project I'll need to do this or something similar. Since I'll be processing data and will be needing to write it on a database.
  1 件のコメント
Luís Marques
Luís Marques 2019 年 8 月 23 日
編集済み: Luís Marques 2019 年 8 月 23 日
Issue solved.
Theres was some issue with prior instructions I tried that ended up creating a bunch of tables (different names) on the database but on the default schema created by postgres.
The thing is that the table I was trying to append to already existed on that default schema, and due to most likely not specifying the schema correctly an error was ocurring.
Later, another issue was raised (which was rasied before and most likely prompted the cascade of wrong instructions I gave the database) concerning the compatibility of the datatypes, with me trying to write datatypes not supported.

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

採用された回答

Urmila Rajpurohith
Urmila Rajpurohith 2019 年 8 月 23 日
Try the example mentioned in the Documentation provided in the below link
If it does not work as expected, try to reinstall the JDBC Driver and try again.
Follow the below mentioned documentation link for establishing connection to the data base
  1 件のコメント
Luís Marques
Luís Marques 2019 年 8 月 23 日
Hi, thank you for your answer.
I eventually solved the problem though I forgot to close the subject by commenting my original post. Will do that now.
Cheers

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

その他の回答 (0 件)

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by