Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
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 commentaire
Luís Marques
Luís Marques le 23 Août 2019
Modifié(e) : Luís Marques le 23 Août 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.

Connectez-vous pour commenter.

Réponse acceptée

Urmila Rajpurohith
Urmila Rajpurohith le 23 Août 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 commentaire
Luís Marques
Luís Marques le 23 Août 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.
Cheers

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by