Re: Unique constraint on field inside composite type. - Mailing list pgsql-general

From Tom Lane
Subject Re: Unique constraint on field inside composite type.
Date
Msg-id 16851.1471915432@sss.pgh.pa.us
Whole thread Raw
In response to Re: Unique constraint on field inside composite type.  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Unique constraint on field inside composite type.  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> On 08/17/2016 11:02 PM, Silk Parrot wrote:
>> CREATE TABLE user (
>> uuid UUID PRIMARY KEY DEFAULT public.uuid_generate_v4(),
>> google_user system.google_user,
>> facebook_user system.facebook_user,
>> UNIQUE (google_user.email)
>> );
>> ERROR:  syntax error at or near "."
>> LINE 10:     UNIQUE (google_user.email)
>>
>> Is there a way to create unique constraint on a field inside composite type?

> I tried David's suggestion:
> (google_user).email
> and that did not work, but it got me to thinking, so:

You'd need additional parens around the whole thing, like

create unique index on "user"(((google_user).email));

The UNIQUE-constraint syntax will never work, because per SQL standard
such constraints can only name simple columns.  But you can make
a unique index separately.

            regards, tom lane


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Why insertion throughput can be reduced with an increase of batch size?
Next
From: Patrick B
Date:
Subject: Re: Permissions pg_dump / import