Re: missing foreign key fails silently using COPY

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: missive(at)hotmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: missing foreign key fails silently using COPY
Date: 2002-02-25 17:24:20
Message-ID: 21994.1014657860@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

missive(at)frontiernet(dot)net (Lee Harr) writes:
> When COPYing data to a table which uses foreign keys, if there
> is a reference to a key which is not there, the copy fails
> (as expected) but there is no error message.

> Hmm. Looking at it more, seems like there is an error message
> when using:
> COPY "f" FROM '/home/lee/f.dat';

> but _not_ when using:
> COPY "f" FROM stdin;
> or
> \copy f from f.dat

This seems to be a libpq and/or psql bug. The error message is reported
in the postmaster log and sent to the frontend --- but libpq evidently
isn't catching it. I suspect that the problem is that the error is
detected during transaction completion, not while the copy is in
progress, and either libpq or psql is dropping the ball about reporting
the error to the user.

I did:

regression=# create table foo(f1 int primary key);
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo'
CREATE
regression=# create table bar(f2 int references foo);
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
CREATE
regression=# copy bar from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> 1
>> \.
regression=#

Looking in postmaster log, I now see
ERROR: <unnamed> referential integrity violation - key referenced from bar not found in foo
but psql sure didn't tell me about it.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2002-02-25 18:55:44 Re: missing foreign key fails silently using COPY
Previous Message Tatsuo Ishii 2002-02-25 13:47:53 Re: [BUGS] Bug #602: Chinese characters query bug.

Browse pgsql-hackers by date

  From Date Subject
Next Message GB Clark 2002-02-25 18:02:17 Re: [HACKERS] Nice Oracle tuning article
Previous Message Bruce Momjian 2002-02-25 17:02:55 Re: decode()