Re: Getting NOT NULL constraint from pg_attribute

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Wu Ivy <ivywuyzl(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Getting NOT NULL constraint from pg_attribute
Date: 2018-08-18 01:02:09
Message-ID: 9894.1534554129@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Wu Ivy <ivywuyzl(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2018-08-18 01:39:32 Re: Fix help option of contrib/oid2name
Previous Message Dave Cramer 2018-08-17 23:39:04 Re: Fix for REFRESH MATERIALIZED VIEW ownership error message