pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedAdding a New Composite Constraint to an Existing Table.
3+ messages / 3 participants
[nested] [flat]
* Adding a New Composite Constraint to an Existing Table.
@ 2002-02-09 10:28 Bhuvan A <bhuvansql@yahoo.com>
0 siblings, 2 replies; 3+ messages in thread
From: Bhuvan A @ 2002-02-09 10:28 UTC (permalink / raw)
To: pgsql-sql
Hi,
I am using postgresql 7.1. I was unable to add a new PRIMARY KEY
constraint to an existing table.
i have table,
CREATE TABLE xx
(
id int,
name text,
amount int
);
I have say some 10 records in this table, which are unique and not
null (primary). Fine! Now, i am willing to have primary key constraint
to all the 3 fields.
I tried,
bhuvan=> ALTER TABLE xx ADD primary key (id, name, amount);
ERROR: ALTER TABLE / ADD CONSTRAINT is not implemented for that
constraint type.
Where i am wrong? How else, can i get that primary key constraint
WITHOUT RECREATING that table?
Hope to get some lights.
Regards,
Bhuvaneswar.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Adding a New Composite Constraint to an Existing Table.
@ 2002-02-09 12:57 MindTerm <mindterm@yahoo.com>
parent: Bhuvan A <bhuvansql@yahoo.com>
1 sibling, 0 replies; 3+ messages in thread
From: MindTerm @ 2002-02-09 12:57 UTC (permalink / raw)
To: Bhuvan A <bhuvansql@yahoo.com>; pgsql-sql
Dear Bhuvaneswar,
Postgresql 7.2 has implemented this feature. For
7.1, I am afraid that you should recreate the table.
M.T.
--- Bhuvan A <bhuvansql@yahoo.com> wrote:
>
> Hi,
>
> I am using postgresql 7.1. I was unable to add a
> new PRIMARY KEY
> constraint to an existing table.
>
> i have table,
> CREATE TABLE xx
> (
> id int,
> name text,
> amount int
> );
>
> I have say some 10 records in this table, which are
> unique and not
> null (primary). Fine! Now, i am willing to have
> primary key constraint
> to all the 3 fields.
>
> I tried,
>
> bhuvan=> ALTER TABLE xx ADD primary key (id, name,
> amount);
> ERROR: ALTER TABLE / ADD CONSTRAINT is not
> implemented for that
> constraint type.
>
> Where i am wrong? How else, can i get that primary
> key constraint
> WITHOUT RECREATING that table?
>
> Hope to get some lights.
>
> Regards,
> Bhuvaneswar.
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
majordomo@postgresql.org
__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Adding a New Composite Constraint to an Existing Table.
@ 2002-02-09 17:43 Stephan Szabo <sszabo@megazone23.bigpanda.com>
parent: Bhuvan A <bhuvansql@yahoo.com>
1 sibling, 0 replies; 3+ messages in thread
From: Stephan Szabo @ 2002-02-09 17:43 UTC (permalink / raw)
To: Bhuvan A <bhuvansql@yahoo.com>; +Cc: pgsql-sql
On Sat, 9 Feb 2002, Bhuvan A wrote:
> I am using postgresql 7.1. I was unable to add a new PRIMARY KEY
> constraint to an existing table.
>
> i have table,
> CREATE TABLE xx
> (
> id int,
> name text,
> amount int
> );
>
> I have say some 10 records in this table, which are unique and not
> null (primary). Fine! Now, i am willing to have primary key constraint
> to all the 3 fields.
>
> I tried,
>
> bhuvan=> ALTER TABLE xx ADD primary key (id, name, amount);
> ERROR: ALTER TABLE / ADD CONSTRAINT is not implemented for that
> constraint type.
>
> Where i am wrong? How else, can i get that primary key constraint
> WITHOUT RECREATING that table?
On 7.1 you need a little magic depending on how exactly you want to
make the primary key. I don't have a 7.1 machine available, but...
You should make a unique index xx_pkey on xx(id, name, amount)
You may want to update pg_index to set the indisprimary for
that index, but I don't think that'll affect the actual running of
the constraint.
You'll then need to set the three columns NOT NULL by something like:
update pg_attribute set attnotnull=true from pg_class where
pg_class.oid=attrelid and relname='xx' and attname in ('id', 'name',
'amount');
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-02-09 17:43 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-09 10:28 Adding a New Composite Constraint to an Existing Table. Bhuvan A <bhuvansql@yahoo.com>
2002-02-09 12:57 ` MindTerm <mindterm@yahoo.com>
2002-02-09 17:43 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox