Re: Cannot declare record members NOT NULL

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Cultural Sublimation <cultural_sublimation(at)yahoo(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Cannot declare record members NOT NULL
Date: 2007-09-13 12:16:24
Message-ID: 20070913121624.GB11110@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Sep 13, 2007 at 05:02:10AM -0700, Cultural Sublimation wrote:
> In OCaml and in other languages with strong type systems, "int4 never NULL"
> and "int4 possibly NULL" are definitely different types. I think the source
> of the problem here is that SQL has a different philosophy, one where type
> constraints are not seen as creating new types.

Well, what SQL thinks has little to do with it (it has DOMAINs for
example). The problem is also that postgres doesn't distinguish between
the two in normal usage. Just about *every* function can return NULL if
given the right circumstances. There is really no way postgres can say
something is never null, unless it comes from a column declared as
such.

> But anyway if you think that checking pg_attribute is a lame method of
> obtaining type information, what do you suggest should be done instead?
> What would you do if it were you creating the bindings?

Firstly, the output of most queries is of a type not represented
anywhere in the catalogs. It's mostly going to be an undeclared record
whose members are listed in pg_type. So using pg_attribute for anything
like this is probably completely wrong.

If I were writing it I would ignore the attisnull flag altogether and
assume that any column can be NULL. If you like you could use the
typisnull column in pg_type, that *is* enforced since that's an actual
constraint on the type.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-09-13 12:21:57 Re: Database/Table Design for Global Country Statistics
Previous Message Stefan Schwarzer 2007-09-13 12:16:03 Re: Database/Table Design for Global Country Statistics