Re: serial type as foreign key referential integrity

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Zhicong Leo Liang <leozc(at)cse(dot)unsw(dot)edu(dot)au>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: serial type as foreign key referential integrity
Date: 2002-09-03 15:44:27
Message-ID: 20020903084246.U46240-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 31 Aug 2002, Zhicong Leo Liang wrote:

> Hi all,
> Just briefly describe my problem.
> I have two tables.
> create table A(
> a1 serial primary key,
> a2 varchars(10)
> );
> create table B(
> b1 integer primary key,
> b2 Integer,
> foreign key(b2) references a(a1)
> )
> insert into A values('123');
> select a1 from A where a2='123'
> >--
> >a1
> >--
> >1
> >--

Did you actually do that sequence and get that result?
Because you shouldn't. That should have put a 123 in a1 and
a NULL in a2.
Perhaps you meant insert into a(a2) values('123');

> insert into B values (1,1);
> ERROR!! referential integrity violation - key referenced from B not found in A.

In any case doing the above (with correction) and the insert
works fine for me. We'll need more info.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Marc G. Fournier 2002-09-03 16:30:18 Re: Just testing tighgter UCE controls ...
Previous Message Michael Meskes 2002-09-03 15:29:45 Re: BYTEA with ecpg