Re: Re: I need help creating a composite type with some sort of constraints. - Mailing list pgsql-general

From Merlin Moncure
Subject Re: Re: I need help creating a composite type with some sort of constraints.
Date
Msg-id b42b73150911241551s118aecc0n4d1da70d3fe6a8d5@mail.gmail.com
Whole thread Raw
In response to Re: I need help creating a composite type with some sort of constraints.  (John Oyler <john.m.oyler@gmail.com>)
Responses Re: Re: I need help creating a composite type with some sort of constraints.  (John Oyler <john.m.oyler@gmail.com>)
Re: Re: I need help creating a composite type with some sort of constraints.  (John Oyler <john.m.oyler@gmail.com>)
List pgsql-general
On Tue, Nov 24, 2009 at 10:13 AM, John Oyler <john.m.oyler@gmail.com> wrote:
>>
>> For now you have to put all checks in custom constructor functions.
>>
>> Scott
>
> I must not be looking in the right place... the only thing I can find that
> seems remotely related, is the page on input/output functions for custom
> types. And I was under the impression that only applies to non-composite
> custom types. Did I miss something?

no...he was basically saying that if you have a constraint that must
be enforced at the type level, you have to go the custom type route.

you can of course write both column constraints and table constraints
that check composite types:

create table foo(a text, b text);
create table bar(f foo check ((f).a != 'test'));

You may also write a table trigger for 'bar' to check the values of
foo. However, constraints are only checked by the table that is
storing the composite. Not on the composite itself (even it it is
defined as a table with a constraint).

Arguably:
create table foz(a text, b text, check (a != 'test'));
select ('test', 'test')::foz;
should fail, but doesn't.

merlin

pgsql-general by date:

Previous
From: silly8888
Date:
Subject: Re: Partitioning table and dynamic SQL in trigger
Next
From: Denis Lussier
Date:
Subject: Re: [PERFORM] Strange performance degradation