Re: how to continue after error in batch mode with psql

From: jr <jorg(dot)raskowski(at)tailorware(dot)org(dot)uk>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: how to continue after error in batch mode with psql
Date: 2010-04-29 10:57:20
Message-ID: hrbomj$1a01$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

hi Urs,

this is perhaps not what you meant but...

I'd use a simple script to filter out the offending lines before they go
into the database, like the following written in Tcl (but you could
write this in almost any language):

----------<snip>----------
#!/usr/bin/tclsh
set fp [open badlines.txt a]
while {0 <= [gets stdin line]} {
set n [string length $line]
if {$n < 1 || $n > 20} {
puts $fp $line
} else {
puts stdout $line
}
}
close $fp
exit 0
----------<snip>----------

now your pipeline becomes:

su - postgres -c "cat test.csv | badlines | psql -X -q test -c \"COPY
t_test FROM stdin WITH DELIMITER AS ',' NULL AS '?' CSV QUOTE AS '\\\"'
ESCAPE AS '\\\"'\""

and you can process the lines in 'badlines.txt' later, at your leisure.

HTH

--

regards, jr. (jr(at)tailorware(dot)org(dot)uk)

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Mick 2010-04-29 13:22:01 Re: pls help me to unsubscribe from this list.
Previous Message bijoy 2010-04-29 10:28:37 pls help me to unsubscribe from this list.