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

From: Florian Pflug <fgp(at)phlo(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, cbbrowne(at)gmail(dot)com, alex-goncharov(at)comcast(dot)net, mmoncure(at)gmail(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: libpq, PQdescribePrepared -> PQftype, PQfmod, no PQnullable
Date: 2011-10-09 17:10:23
Message-ID: 438AC743-23AD-4086-8DDF-9BA4F551407B@phlo.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Oct9, 2011, at 17:56 , Tom Lane wrote:
> Florian Pflug <fgp(at)phlo(dot)org> writes:
>> On Oct9, 2011, at 14:20 , Kevin Grittner wrote:
>>> Yeah. It would be nice to see at least one use case. The only
>>> comment I recall is a vague suggestion that that people might want to
>>> select data from a table and infer table attributes from the result
>>> set metadata. That seems marginal.
>
>> Well, there is one other, namely SQL standards compliance. It does
>> mandate that "CREATE TABLE ... AS SELECT" creates NOT NULL constraints
>> on non-nullable columns I think (I didn't re-check, though). I'm not sure
>> I see the value in that either, but, hey, standards compliance ought
>> to be a value it in itself, right?
>
> Um ... but that case has nothing to do with protocol changes.

No, that was meant as a use-case for the deduction of nullability, not
for it's transmission to the client. While those are obviously two distinct
things, I figured we'd probably tackle them at the same time (if ever). It'd
be strange to infer NOT NULL constraints for CREATE TABLE ... AS SELECT, yet
provide no way for clients to obtain that information for simple SELECT
statements.

And you're right, the Wiki already contains a wish list for the next protocol
version, and that wish list includes an entry for extending Describe to report
the nullability of columns. The entry, BTW, was added by one Tom Lane ;-)

The wish list can be found on http://wiki.postgresql.org/wiki/Todo under
"Wire Protocol Changes". The referenced thread on -hackers includes a rather
interesting use-case.

The idea presented there is to infer the type of a statement's result columns
at application compile-time, and inject the result into the compiler's type
checking and deduction algorithm. Since most statically types languages don't
have a general concept of "undefined" (i.e., there's no special "undefined" value
included in the domain of every type), there's a lot of value in knowing that a
columns cannot be null. It allows you to map the column directly to a string, int
or whatever on the client side, instead of going through some intermediate type
which adds "undefined" to the list of possible values. (That "intermediate type"
is the "Maybe" monad in Haskell, in C++ it'd be boost::optional or something
similar)

best regards,
Florian Pflug

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alex Hunsaker 2011-10-09 17:56:08 Re: alter table only ... drop constraint broken in HEAD
Previous Message Tom Lane 2011-10-09 16:06:34 Re: Range Types - typo + NULL string constructor