better error handling for COPY from stdin

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: better error handling for COPY from stdin
Date: 2008-04-22 14:02:17
Message-ID: 20080422140217.GA12194@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

if you have .sql file with COPY table FROM stdin;
and the table doesn't exist, psql prints a lot of errors from lines
which contain only data for copy.

to reproduce:
=> echo -ne "COPY non_existing_table FROM stdin;\n1\n\\N\n2\n\\.\n" | psql
ERROR: relation "non_existing_table" does not exist
invalid command \N
invalid command \.
ERROR: syntax error at or near "1"
LINE 1: 1
^

would it be possible to make it smarter, so it will not treat datalines from
failed copy as statements?

i see a lot of questions that "postgresql says command \N is invalid" - which
is of course rubbish, but making psql a bit smarter would make all of these
question go away.

regards,

depesz

--
quicksil1er: "postgres is excellent, but like any DB it requires a
highly paid DBA. here's my CV!" :)
http://www.depesz.com/ - blog dla ciebie (i moje CV)

Browse pgsql-general by date

  From Date Subject
Next Message Erik Jones 2008-04-22 14:21:51 Re: How is statement level read consistency implemented?
Previous Message Joris Dobbelsteen 2008-04-22 13:52:10 Re: table as log (multiple writers and readers)