Re: constraints on composite types

From: Richard Huxton <dev(at)archonet(dot)com>
To: Roman Neuhauser <neuhauser(at)sigpipe(dot)cz>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: constraints on composite types
Date: 2005-09-09 12:53:54
Message-ID: 432185E2.5010000@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Roman Neuhauser wrote:
> This fails on 8.0.3 (syntax error at or near "." at character):
>
> CREATE TYPE ct AS (
> foo INTEGER,
> bar INTEGER
> );
>
> CREATE TABLE t1 (
> attr ct,
> CONSTRAINT uq UNIQUE (attr.foo)
> );
>
> Should it be possible? From reading
> http://www.postgresql.org/docs/current/static/rowtypes.html it looks
> like almost everything else works.

You might get somewhere with:

CREATE OR REPLACE FUNCTION testfunc(ct) RETURNS int AS
'SELECT $1.foo;'
LANGUAGE SQL IMMUTABLE;

CREATE UNIQUE INDEX t1_b_uniq ON t1 (testfunc(b));

Seems to work on 8.1beta - haven't tried on version 8, but if the syntax
is accepted I don't see why not.
--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John D. Burger 2005-09-09 13:06:17 Re: SQL - planet redundant data
Previous Message Michael Fuhr 2005-09-09 12:45:01 Re: Is this a bug or am I doing something wrong?