Re: Getting NOT NULL constraint from pg_attribute - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Getting NOT NULL constraint from pg_attribute
Date
Msg-id 9894.1534554129@sss.pgh.pa.us
Whole thread Raw
In response to Getting NOT NULL constraint from pg_attribute  (Wu Ivy <ivywuyzl@gmail.com>)
Responses Re: Getting NOT NULL constraint from pg_attribute
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: Dave Cramer
Date:
Subject: Re: Fix for REFRESH MATERIALIZED VIEW ownership error message
Next
From: Michael Paquier
Date:
Subject: Re: Fix help option of contrib/oid2name