Re: Getting NOT NULL constraint from pg_attribute

Поиск
Список
Период
Сортировка
От Wu Ivy
Тема Re: Getting NOT NULL constraint from pg_attribute
Дата
Msg-id 4C9A329E-A6D5-4240-8919-BB6397BF8739@gmail.com
обсуждение исходный текст
Ответ на Re: Getting NOT NULL constraint from pg_attribute  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Getting NOT NULL constraint from pg_attribute
Список pgsql-hackers
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 <tgl@sss.pgh.pa.us> wrote:

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 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

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Chris Travers
Дата:
Сообщение: Re: Two proposed modifications to the PostgreSQL FDW
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Getting NOT NULL constraint from pg_attribute