Re: libpq, PQdescribePrepared -> PQftype, PQfmod, no PQnullable

From: Florian Pflug <fgp(at)phlo(dot)org>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Alex Goncharov <alex-goncharov(at)comcast(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: libpq, PQdescribePrepared -> PQftype, PQfmod, no PQnullable
Date: 2011-10-06 21:16:53
Message-ID: 1100967F-75CD-4720-95FE-4552B3ADFDC9@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Oct6, 2011, at 22:38 , Merlin Moncure wrote:
> On Thu, Oct 6, 2011 at 3:22 PM, Alex Goncharov
> <alex-goncharov(at)comcast(dot)net> wrote:
>> ,--- I/Alex (Thu, 06 Oct 2011 14:02:14 -0400) ----*
>> | My understanding is that libpq does not allow one to find if a result
>> | set column is nullable.

>> ,--- You/Merlin (Thu, 6 Oct 2011 15:16:18 -0500) ----*
>> | why aren't you using PQgetisnull()?
>>
>> This function is not about the nullability of a column but rather
>> about the value in a result set cell:
>>
>> PQgetisnull: Tests a field for a null value.
>>
>> int PQgetisnull(const PGresult *res, int row_number, int column_number);
>>
>> Notice the 'row_number'.
>
> right -- get it. well, your question is doesn't make sense then --
> any column can be transformed in ad hoc query, so it only makes sense
> to test individual values post query.. btw, if you don't like
> querying system catalogs, check out information_schema.columns.

Sure, but there are still a lot of cases where the database could deduce
(quite easily) that a result column cannot be null. Other databases do
that - for example, I believe to remember that Microsoft SQL Server preserves
NOT NULL constraints if you do

CREATE TABLE bar AS SELECT * from foo;

So the question makes perfect sense, and the answer is: No, postgres currently
doesn't support that, i.e. doesn't deduce the nullability of result columns,
not even in the simplest cases.

best regards,
Florian Pflug

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2011-10-06 21:28:56 Re: libpq, PQdescribePrepared -> PQftype, PQfmod, no PQnullable
Previous Message Merlin Moncure 2011-10-06 20:38:59 Re: libpq, PQdescribePrepared -> PQftype, PQfmod, no PQnullable