How to Get Only the First Error with psql –single-transaction in PostgreSQL

errorspostgresqlpsql

I'm typing something like:

psql --single-transaction --quiet my_db < my_file.sql

When the script fails I get many lines saying: current transaction is aborted, commands ignored until end of transaction block.

In linux I can use | more to pipe the result, but in Windows thats may take a lot of time (to show the first error, because the pipe is not a pipe).

My question:

Is there a way to get only the first error?

  • The .sql file is generated by me, I can add some sets or commands if necesary
  • Y try –file (I obtain the same behavior)

Best Answer

You may just ask it to stop on the first error:

$ psql -v ON_ERROR_STOP=on --single-transaction ...