Skip site navigation (1) Skip section navigation (2)

Re: Howto define a constraint in a existing column

From: Intengu Technologies <sindile(dot)bidla(at)gmail(dot)com>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Howto define a constraint in a existing column
Date: 2009-08-09 10:15:15
Message-ID: a1afa64b0908090315l2c837008pbac13d7803037b38@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Thanks worked like a charm

On 09/08/2009, Thomas Kellerer <spam_eater(at)gmx(dot)net> wrote:
> Intengu Technologies wrote on 09.08.2009 11:23:
>> I am tying to define a primary key constraint to an existing table,
>> this is what I have tried so far
>>
>> ALTER TABLE mytable ALTER COLUMN field13 CONSTRAINT name PRIMARY KEY;
>>
>> I get the following error: ERROR: syntax error at or near "CONSTRAINT"
>> SQL state: 42601
>> Character: 61
>>
> That should be
>
> ALTER TABLE mytable
>     ADD PRIMARY KEY (field13);
>
> Or if you want to give the constraint a name:
>
> ALTER TABLE mytable
>     ADD CONSTRAINT pk_mytable PRIMARY KEY (field13);
>
> Thomas
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>


-- 
Sindile Bidla

In response to

pgsql-novice by date

Next:From: Bruce MomjianDate: 2009-08-09 18:13:46
Subject: Re: Veritas netbackup live backup?
Previous:From: Thomas KellererDate: 2009-08-09 09:32:49
Subject: Re: Howto define a constraint in a existing column

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group