Lists: | pgsql-sql |
---|
From: | Wei Weng <wweng(at)kencast(dot)com> |
---|---|
To: | "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org> |
Subject: | How do I quit in the middle of a SQL script? |
Date: | 2005-05-20 17:22:42 |
Message-ID: | 428E1CE2.2050605@kencast.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Say if I want to add a small snip of code in front of the sql script
generated by the pg_dump, to check for something then if the condition
doesn't match, the script terminates right away. (Without actually doing the
restoring stuff that the following large chunk is supposed to do)
Can I do that? And is it a good idea to add arbitrary code to the database
dump sql script?
Thanks!
Wei
From: | John DeSoi <desoi(at)pgedit(dot)com> |
---|---|
To: | Wei Weng <wweng(at)kencast(dot)com> |
Cc: | "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: How do I quit in the middle of a SQL script? |
Date: | 2005-05-20 18:36:53 |
Message-ID: | 5b3405142791217e121ed0e38f790ac9@pgedit.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
On May 20, 2005, at 1:22 PM, Wei Weng wrote:
> Say if I want to add a small snip of code in front of the sql script
> generated by the pg_dump, to check for something then if the condition
> doesn't match, the script terminates right away. (Without actually
> doing the restoring stuff that the following large chunk is supposed
> to do)
>
> Can I do that?
Put this at the start of the file to make psql stop if there is an
error:
\set ON_ERROR_STOP 1
> And is it a good idea to add arbitrary code to the database dump sql
> script?
No problem if you know what you are doing and/or have good backups :)
John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL
From: | Mischa Sandberg <mischa(dot)sandberg(at)telus(dot)net> |
---|---|
To: | Wei Weng <wweng(at)kencast(dot)com>, "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: How do I quit in the middle of a SQL script? |
Date: | 2005-05-20 20:51:45 |
Message-ID: | 1116622305.428e4de1790dc@webmail.telus.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-sql |
Quoting John DeSoi <desoi(at)pgedit(dot)com>:
>
> On May 20, 2005, at 1:22 PM, Wei Weng wrote:
>
> > Say if I want to add a small snip of code in front of the sql script
> > generated by the pg_dump, to check for something then if the condition
> > doesn't match, the script terminates right away. (Without actually
> > doing the restoring stuff that the following large chunk is supposed
> > to do)
> >
> > Can I do that?
>
> Put this at the start of the file to make psql stop if there is an
> error:
>
> \set ON_ERROR_STOP 1
>
> > And is it a good idea to add arbitrary code to the database dump sql
> > script?
>
> No problem if you know what you are doing and/or have good backups :)
You don't have to:
pg_restore mydb.dump | psql --set ON_ERROR_STOP=1