I assume you are using psql , it may be convenient to add ~/.psqlrc to your file.
\set ON_ERROR_STOP on
This will interrupt the first error. If you do not have it, even with a transaction, it will continue to execute your script, but will not work until the end of your script.
And you probably want to use a transaction, as Paul said. What can also be done with psql --single-transaction ... if you do not want to modify the script.
So, a complete example: with ON_ERROR_STOP in your .psqlrc:
psql
plundra Dec 18 '10 at 23:40 2010-12-18 23:40
source share