I'm loading an exported database with the below commands:
psql -c 'drop database database1'
psql -c 'create database database1'
psql database1 < script.sql
Now I'm trying to check if the final command succeeded:
if [[ $? -eq 0 ]]; then
echo "OK."
else
echo "Not OK."
fi
This always outputs "OK." the Exit code is always 0, even if script.sql
completes with errors:
psql database1 < script.sql
ERROR: constraint "test_id" for relation "test" already exists
echo $?
0
How can I confirm the sql import succeeded?