Wu Ivy <ivywuyzl@gmail.com> writes:
> I’m currently building a Postgres C extension that fetch data from a Postgres table.
> Since the table can be large, in order to prevent memory overrun, I use SPI_cursor_fetch to fetch chunks of data. The
resultrows are saved in SPITupleTable* SPI_tuptable and attributes are saved in SPI_tuptable->tupdesc.
> In order to process my data, I need to get information of column nullability (whether column has NOT NULL constrain).
Ican get this information by calling:
> TupleDesc tupdesc = SPI_tuptable->tupdesc;
> bool is_nullable = TupleDescAttr(tupdesc, column_num - 1) -> attnotnull;
> However, the result (is_nullable) is always 0, meaning the column does not have NOT NULLl constraint, even for
columnsthat do have the NOT NULL constraint.
The output columns of a SELECT query are never marked nullable, regardless
of what the source data was.
regards, tom lane