Re: table inheritance and foreign key troubles
От | Stephan Szabo |
---|---|
Тема | Re: table inheritance and foreign key troubles |
Дата | |
Msg-id | Pine.BSF.4.21.0109110349380.20489-100000@megazone23.bigpanda.com обсуждение исходный текст |
Ответ на | Re: table inheritance and foreign key troubles (Christof Glaser <gcg@gl.aser.de>) |
Список | pgsql-sql |
(hopefully this doesn't double post... stupid mail system) On Tue, 11 Sep 2001, Christof Glaser wrote: > On Tuesday, 11. September 2001 10:04, Kevin Way wrote: > > I'm having a little trouble with some inherited tables and a foreign > > key. Here's a simplified case, to show the trouble. > > > > CREATE TABLE node ( > > node_id SERIAL NOT NULL, > > name TEXT NOT NULL, > > PRIMARY KEY (node_id) > > ); > > -- works just fine > > > > CREATE TABLE users ( > > email TEXT NOT NULL > > ) INHERITS (node); > > -- so far so good.... > > > > CREATE TABLE item ( > > reason TEXT NOT NULL, > > author_id INT NOT NULL REFERENCES users (node_id) > > ) INHERITS (node); > > ERROR: UNIQUE constraint matching given keys for referenced table > > "users" not found > > That means, there is no UNIQUE constraing on users.node_id ;-) > Since users inherits that field from node, just make node.node_id > unique, or even a primary key. Actually node.node_id looks to be a pkey, but primary keys/unique don't inherit, so users.node_id doesn't have the constraint. You'll need a primary key(node_id) on users as well (note that this won't actually enforce that values are unique across both node and users just within each table. See past discussions about inheritance and foreign keys...
В списке pgsql-sql по дате отправления: