1

I'm using psql to connect to a Redshift database. Redshift doesn't seem to support \set ON_ERROR_STOP TRUE so I can't use that to stop the query and direct something to error output.

Is there another way to catch any error from a psql connection or query? So if the connection fails or the query didn't succeed, I want to just catch that an error was thrown and do another command.

simplycoding
  • 2,770
  • 9
  • 46
  • 91

1 Answers1

2

Can you post your script ? What do you mean by "not support \set ON_ERROR_STOP TRUE" ? When you use that, you need to catch the return value like :

 psql yourDataBase -U yourUserName <<EOF 
    \set ON_ERROR_STOP TRUE     
    YOUR_SCRIPT az
 EOF
 ERRCODE=$?

So, ERRCODE will get value:

  • 0 = success,
  • 1 & 2 = database connectivity,
  • 3 = script code error.
FTK
  • 185
  • 1
  • 2
  • 13