Re: Creating unique constraints on OID

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Creating unique constraints on OID
Date: 2001-10-22 22:53:59
Message-ID: 27897.1003791239@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Shouldn't this work?
> create table test ( a int, unique (oid) );
> ERROR: CREATE TABLE: column "oid" named in key does not exist

Now it does.

regression=# create table test ( a int, unique (oid) );
NOTICE: CREATE TABLE/UNIQUE will create implicit index 'test_oid_key' for table 'test'
CREATE
regression=# drop table test;
DROP
regression=# create table test ( a int, unique (oid) ) without oids;
ERROR: CREATE TABLE: column "oid" named in key does not exist
regression=# create table test ( a int ) without oids;
CREATE
regression=# alter table test add unique (oid);
ERROR: ALTER TABLE: column "oid" named in key does not exist
regression=# drop table test;
DROP
regression=# create table test ( a int );
CREATE
regression=# alter table test add unique (oid);
NOTICE: ALTER TABLE/UNIQUE will create implicit index 'test_oid_key' for table 'test'
CREATE
regression=#

> And shouldn't the last one say "ALTER"?

The reason that happens is that parser/analyze.c transforms the command
into an ALTER TABLE step that adds a constraint (a no-op in this case)
plus a CREATE INDEX step. The commandTag emitted by the last step is
what psql shows. This could possibly be fixed, but it seems not worth
the trouble.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-10-22 23:13:10 Re: Does "postmaster -i"...
Previous Message speedboy 2001-10-22 22:52:05 Re: createlang difficulty.