Re: Unique constraint on field inside composite type.

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Silk Parrot <silkparrot(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Unique constraint on field inside composite type.
Date: 2016-08-23 02:55:17
Message-ID: bcfd250f-d5e7-99e8-e76a-a0e77a646679@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/22/2016 06:23 PM, Tom Lane wrote:
> Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)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));

Aah, I did not bury it deep enough, my attempt:

create unique index g_u on test_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
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jerome Wagner 2016-08-23 10:04:15 question on error during COPY FROM
Previous Message Tom Lane 2016-08-23 01:41:14 Re: Permissions pg_dump / import