Getting NOT NULL constraint from pg_attribute

From: Wu Ivy <ivywuyzl(at)gmail(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Getting NOT NULL constraint from pg_attribute
Date: 2018-08-17 23:25:05
Message-ID: FCF4AD17-CBFF-472C-BCAF-B20CBE3C9C3F@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi developers,

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.

Any idea of why is it happening?
Thanks in advance!

Best,
Ivy

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dave Cramer 2018-08-17 23:32:09 Re: Fix for REFRESH MATERIALIZED VIEW ownership error message
Previous Message Alvaro Herrera 2018-08-17 22:30:30 Re: Fix for REFRESH MATERIALIZED VIEW ownership error message