MATLAB Answers

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

조회 수: 13(최근 30일)
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', ...
Table.Properties.VariableNames = ColumnNames;
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 23 Aug 2019
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.

로그인 to comment.

채택된 답변

Urmila Rajpurohith
Urmila Rajpurohith 23 Aug 2019
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 23 Aug 2019
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.

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by