Y
Yoann M.
Hello,
I use the 'pg' gem to send some data files to a postgresql database. I
use the 'COPY ... FROM ...' query, on STDIN. Looks like this :
db.exec("COPY t(a, b, c) FROM STDIN WITH DELIMITER '\t' csv QUOTE ''''")
file = File.open("filename", "r")
file.each_line { |line| db.put_copy_data(line) }
db.put_copy_end
It works. If I try to run a bad SQL query I get a PGError exception. If
I try to run it with bad data files, I get no exception but the data is
not (or not entirely) put in the database. The same data file with a
copy command runned in psql will fail and display an error.
Is there a way to know when the copy fails from the ruby program ? and
get the error message ?
Thanks
I use the 'pg' gem to send some data files to a postgresql database. I
use the 'COPY ... FROM ...' query, on STDIN. Looks like this :
db.exec("COPY t(a, b, c) FROM STDIN WITH DELIMITER '\t' csv QUOTE ''''")
file = File.open("filename", "r")
file.each_line { |line| db.put_copy_data(line) }
db.put_copy_end
It works. If I try to run a bad SQL query I get a PGError exception. If
I try to run it with bad data files, I get no exception but the data is
not (or not entirely) put in the database. The same data file with a
copy command runned in psql will fail and display an error.
Is there a way to know when the copy fails from the ruby program ? and
get the error message ?
Thanks