From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
---|---|
To: | Florian Weimer <fweimer(at)bfk(dot)de> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Foreign keys, table inheritance, and TRUNCATE |
Date: | 2007-01-30 14:50:18 |
Message-ID: | 20070130145018.GA2303@alvh.no-ip.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Florian Weimer wrote:
> Here's something I've just noticed:
>
> CREATE TABLE foo (f INTEGER PRIMARY KEY);
> INSERT INTO foo VALUES (1);
> CREATE TABLE bar (b INTEGER REFERENCES foo);
> CREATE TABLE bar1 () INHERITS (bar);
> INSERT INTO bar1 VALUES (1);
>
> This is quite correct:
No, it isn't; try leaving the first INSERT out:
alvherre=# CREATE TABLE foo (f INTEGER PRIMARY KEY);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "foo_pkey" for table "foo"
CREATE TABLE
alvherre=# CREATE TABLE bar (b INTEGER REFERENCES foo);
CREATE TABLE
alvherre=# CREATE TABLE bar1 () INHERITS (bar);
CREATE TABLE
alvherre=# INSERT INTO bar1 VALUES (1);
INSERT 0 1
alvherre=# select * from bar;
b
---
1
(1 fila)
alvherre=# select * from foo;
f
---
(0 filas)
There is a bug here, but it's not in TRUNCATE. FKs don't work with
inheritance.
--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2007-01-30 14:59:50 | Re: Retrieving PK of inserted row |
Previous Message | Ron Johnson | 2007-01-30 14:10:01 | Re: PG Email Client |