| From: | Richard Huxton <dev(at)archonet(dot)com> |
|---|---|
| To: | Oleg Bartunov <oleg(at)sai(dot)msu(dot)su> |
| Cc: | Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: serial as FK ? |
| Date: | 2005-02-28 09:46:24 |
| Message-ID: | 4222E870.7020509@archonet.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Oleg Bartunov wrote:
> Hi there,
>
> what's wrong to use SERIAL as FK without explicit PRIMARY KEY or UNIQUE ?
>
> qq=# create table t1( id serial);
> NOTICE: CREATE TABLE will create implicit sequence "t1_id_seq" for
> "serial" column "t1.id"
> CREATE TABLE
> qq=# create table t2( id2 int4 references t1(id));
> ERROR: there is no unique constraint matching given keys for referenced
> table "t1"
>
> btw, Richard, I noticed this problem when looked into your example database
> http://www.archonet.com/pgdocs/chap-exdb.html#EXAMPLE-TABLES
Ah - IIRC there *was* nothing wrong with it when those notes were
written (and I need to update them, clearly). Back then SERIAL implied
UNIQUE too, but that was changed (in 7.3 I believe).
--
Richard Huxton
Archonet Ltd
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Simone Brunozzi | 2005-02-28 10:34:04 | Re: [HACKERS] Development Plans |
| Previous Message | Oleg Bartunov | 2005-02-28 09:26:06 | serial as FK ? |