Hi tom,

Thanks for the quick respond.
Why are SELECT query never marked nullable? For nullable columns, when I call 
SPI_getvalue(), the result (in char*) is NULL. I don’t think I’m too clear on 
the definition of attnotnull. Can you give me a example in which the tupleTable 
is can be marked nullable?
Also, is there any other ways to get nullability of each column while getting 
the data from SPI_cursor_fetch? The only way I can think is to call another 
separate command to query the table schema, but it will be in a separate 
transaction in that case.

Thank you again!
Best,
Ivy
> On Aug 17, 2018, at 6:02 PM, Tom Lane <t...@sss.pgh.pa.us> wrote:
> 
> Wu Ivy <ivywu...@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 result rows 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). I can 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 columns that 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

Reply via email to