sqlwrite doesn't play well with generated column

조회 수: 13 (최근 30일)
Gregory
Gregory 2022년 9월 19일
댓글: Gregory 2022년 9월 27일
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
Geoff Hayes
Geoff Hayes 2022년 9월 23일
@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 2022년 9월 27일
@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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Historical Contests에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by