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