Обсуждение: Syntax error in DROP CONSTRAINT

Поиск
Список
Период
Сортировка

Syntax error in DROP CONSTRAINT

От
"Rajan Bhide"
Дата:
Hi Forum,

I need to add a colume to existing composite primary key on a table.
I tried using following:
>> ALTER TABLE DROP CONSTRAINT tablename_pkey;
>> ALTER TABLE ADD CONSTRAINT PRIMARY KEY (col1, col2, col3, new_col4);

When I try this using Postgres 7.2.4 I get psql syntax error in DROP
CONSTRAINT.
ERROR:  parser: parse error at or near ";"

E.g:
CREATE TABLE forwardinginfo
(
    traptype smallint,
    trapnumber smallint,
        ipaddr varchar ( 16 ),
    port integer DEFAULT 162,
        snmpversion smallint,
    PRIMARY KEY ( traptype, trapnumber, ipaddr, port )
);

ALTER TABLE forwardinginfo DROP CONSTRAINT forwardinginfo_pkey;
**** ERROR:  parser: parse error at or near ";" ****

I want to add the new column after droping the existing constraint.
ALTER TABLE forwardinginfo ADD CONSTRAINT PRIMARY KEY ( traptype,
trapnumber, ipaddr, port, snmpversion);


If I try the same thing with the latest 7.5 version, I see NO error.
How do I perform this with my 7.2.4 postgresql version server?


Thanks,
Rajan.




Re: Syntax error in DROP CONSTRAINT

От
Stephan Szabo
Дата:
On Wed, 17 Nov 2004, Rajan Bhide wrote:

> Hi Forum,
>
> I need to add a colume to existing composite primary key on a table.
> I tried using following:
> >> ALTER TABLE DROP CONSTRAINT tablename_pkey;
> >> ALTER TABLE ADD CONSTRAINT PRIMARY KEY (col1, col2, col3, new_col4);
>
> When I try this using Postgres 7.2.4 I get psql syntax error in DROP
> CONSTRAINT.
> ERROR:  parser: parse error at or near ";"

I believe 7.2 requires RESTRICT at the end and the online docs imply that
it won't remove primary keys in any case so you'll probably need to drop
the index that was created for the constraint instead of using DROP
CONSTRAINT.