sqlwrite doesn't play well with generated column

13 visualizzazioni (ultimi 30 giorni)
Gregory
Gregory il 19 Set 2022
Commentato: Gregory il 27 Set 2022
In my Postgresql database there is a generated 'date' column of type datetime that is generated from a timestamp column. If I omit this column when using sqlwrite, I get an error in line 155 of sqlwrite.m, which complains that the column after doesn't have the proper datetime type. This is odd behavior, but looking at the sqlwrite code, it checks the data types from the connection object and I could imagine something fishy is happening here.
If instead I try to pass an NaT to the "date" value, it passes line 155 of sqlwrite, but of course the database is unhappy, because I'm trying to write to a generated value, supposedly with a string "NaT" or something.
Even weirder is that everything works as long as I don't try to write to the "date" column AND don't write to both of the columns on either side of it. If I only write to one of them, regardless which, it works.
This seems like an edge case that wasn't checked or maybe there's a flag or something I need to set for generated columns. Anyone have any ideas?
  4 Commenti
Geoff Hayes
Geoff Hayes il 23 Set 2022
@Gregory - that is a very interesting analysis of the way in which sqlwrite is working. I wonder if the MATLAB code is not making use of the column names (that you provide in the table) and instead rely simply on column order (which is what your analysis seems to suggest) and assumes that the order has to match the table order. Perhaps someone at @MathWorks Support Team can provide some insight.
Gregory
Gregory il 27 Set 2022
@Geoff Hayes: yes, I believe sqlwrite is just reading the column names from the connection object, instead of the column names from the table I provide as an argument, and therefore uses column order to infer which column I want. Thank you for the response; I also hope @MathWorks Support Team will look into this.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Historical Contests in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by