Dumb question: How do I determine programmatically if a column is nullable?

Started by Dann Corbitabout 22 years ago4 messages
#1Dann Corbit
DCorbit@connx.com

What API call can I make to find out if a column is nullable or not?

#2Andreas Pflug
pgadmin@pse-consulting.de
In reply to: Dann Corbit (#1)
Re: Dumb question: How do I determine programmatically

Dann Corbit wrote:

What API call can I make to find out if a column is nullable or not?

SELECT attnotnull FROM pg_attribute ...
see documentation "Internals/System Catalogs"

Regards,
Andreas

#3Dann Corbit
DCorbit@connx.com
In reply to: Dann Corbit (#1)
Re: Dumb question: How do I determine programmatically if a column is nullable?

-----Original Message-----
From: Andreas Pflug [mailto:pgadmin@pse-consulting.de]
Sent: Wednesday, January 07, 2004 11:17 AM
To: Dann Corbit
Cc: pgsql-hackers@postgresql.org
Subject: Re: [HACKERS] Dumb question: How do I determine
programmatically if a column is nullable?

Dann Corbit wrote:

What API call can I make to find out if a column is nullable or not?

SELECT attnotnull FROM pg_attribute ...
see documentation "Internals/System Catalogs"

Is there a way do do it when I have some arbitrary query that returns a
result set?

In other words, I will be passed a SQL query. I don't want to have to
parse it myself.

Rather, I want to know (for the bound columns) if a column is nullable
or not.

Is the functionality available in [for example] libpq?

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dann Corbit (#3)
Re: Dumb question: How do I determine programmatically if a column is nullable?

"Dann Corbit" <DCorbit@connx.com> writes:

In other words, I will be passed a SQL query. I don't want to have to
parse it myself.
Rather, I want to know (for the bound columns) if a column is nullable
or not.
Is the functionality available in [for example] libpq?

As of 7.4, see PQftable() and PQftablecol(), and look into pg_attribute
to see whether the column is marked NOTNULL.

regards, tom lane