sqlwrite doesn't play well with generated column

14 views (last 30 days)
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 Comments
Geoff Hayes
Geoff Hayes on 23 Sep 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 on 27 Sep 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.

Sign in to comment.

Answers (0)

Categories

Find more on Historical Contests in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!