Re: Cannot declare record members NOT NULL

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Cannot declare record members NOT NULL
Дата
Msg-id 20070913121624.GB11110@svana.org
обсуждение исходный текст
Ответ на Re: Cannot declare record members NOT NULL  (Cultural Sublimation <cultural_sublimation@yahoo.com>)
Ответы Re: Cannot declare record members NOT NULL  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: Stefan Schwarzer
Дата:
Сообщение: Re: Database/Table Design for Global Country Statistics
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: Database/Table Design for Global Country Statistics