pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6054: Insert to table, which has fkey to table, which is parenttable for another table - error
2+ messages / 2 participants
[nested] [flat]

* BUG #6054: Insert to table, which has fkey to table, which is parenttable for another table - error
@ 2011-06-07 12:44  Alex <alexander.ochkalyuk@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Alex @ 2011-06-07 12:44 UTC (permalink / raw)
  To: pgsql-bugs


The following bug has been logged online:

Bug reference:      6054
Logged by:          Alex
Email address:      alexander.ochkalyuk@gmail.com
PostgreSQL version: 8.4.8
Operating system:   CentOS
Description:        Insert to table, which has fkey to table,which is
parenttable for another table - error
Details: 

CREATE TABLE t1 
(t1_id numeric(10,0) NOT NULL PRIMARY KEY);

CREATE TABLE t2
(t2_id numeric(10,0) NOT NULL PRIMARY KEY) INHERITS (t1);


CREATE TABLE t3
(t3_id numeric(10,0) NOT NULL PRIMARY KEY ,
t1_id numeric(10,0) NOT NULL REFERENCES t1(t1_id)) ;



INSERT INTO t2 VALUES(1,2);
INSERT INTO t3 VALUES(3,1);


ERROR:  insert or update on table "t3" violates ---
foreign key constraint "t3_t1_id_fkey"
     DETAIL:  Key (t1_id)=(1) is not present in table "t1".


BUT!!!! 
SELECT t1_id FROM t1 WHERE t1_id = 1;
-->1



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #6054: Insert to table, which has fkey to table,which is parenttable for another table - error
@ 2011-06-16 19:40  Robert Haas <robertmhaas@gmail.com>
  parent: Alex <alexander.ochkalyuk@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Robert Haas @ 2011-06-16 19:40 UTC (permalink / raw)
  To: Alex <alexander.ochkalyuk@gmail.com>; +Cc: pgsql-bugs

On Tue, Jun 7, 2011 at 8:44 AM, Alex <alexander.ochkalyuk@gmail.com> wrote:
>
> The following bug has been logged online:
>
> Bug reference:      6054
> Logged by:          Alex
> Email address:      alexander.ochkalyuk@gmail.com
> PostgreSQL version: 8.4.8
> Operating system:   CentOS
> Description:        Insert to table, which has fkey to table,which is
> parenttable for another table - error
> Details:
>
> CREATE TABLE t1
> (t1_id numeric(10,0) NOT NULL PRIMARY KEY);
>
> CREATE TABLE t2
> (t2_id numeric(10,0) NOT NULL PRIMARY KEY) INHERITS (t1);
>
>
> CREATE TABLE t3
> (t3_id numeric(10,0) NOT NULL PRIMARY KEY ,
> t1_id numeric(10,0) NOT NULL REFERENCES t1(t1_id)) ;
>
>
>
> INSERT INTO t2 VALUES(1,2);
> INSERT INTO t3 VALUES(3,1);
>
>
> ERROR:  insert or update on table "t3" violates ---
> foreign key constraint "t3_t1_id_fkey"
>     DETAIL:  Key (t1_id)=(1) is not present in table "t1".
>
>
> BUT!!!!
> SELECT t1_id FROM t1 WHERE t1_id = 1;
> -->1

When you use a foreign key with inheritance, only the rows that are
actually in the parent table itself are considered for purposes of the
foreign key.

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-06-16 19:40 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-06-07 12:44 BUG #6054: Insert to table, which has fkey to table, which is parenttable for another table - error Alex <alexander.ochkalyuk@gmail.com>
2011-06-16 19:40 ` Re: BUG #6054: Insert to table, which has fkey to table,which is parenttable for another table - error Robert Haas <robertmhaas@gmail.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