libpg_query icon indicating copy to clipboard operation
libpg_query copied to clipboard

Question about ColumnDef.is_not_null always set to false

Open lelit opened this issue 1 year ago • 1 comments

I have been asked (here) about the fact that the is_not_null flag of a ColumnDef is always false.

I tried to determine whether it was a fault of pglast, but inspecting libpg_query sources I suspect that the additional transformation steps that PG applies to the ColumnDef nodes thru transformCreateStmt() were removed with a reason and are probably not useful (or even harmful) in the context of libpg_query (and in transition of pglast).

Am I correct?

lelit avatar Jun 15 '24 08:06 lelit

@lelit Thanks for forwarding the question!

I believe that is because is_not_null is set by the parse-analysis stage of Postgres (e.g. in transformColumnDefinition), which occurs after the raw parser. libpg_query only covers the raw parser, and not any later stages.

I'd recommend doing analysis on the elements that are set by the raw parser instead, they should generally cover the same information (unless the information is only available in internal Postgres catalog tables, as is the case for some type definitions for example).

lfittl avatar Jun 24 '24 23:06 lfittl