pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

Allow users to change the ON_ERROR behavior at runtime.

Open amjith opened this issue 10 years ago • 2 comments

Ref: http://stackoverflow.com/questions/4480381/postgres-sql-fail-on-script-error

pgcli currently supports changing the on-error behavior when we run multiple statements. But this is controlled via the config file. It'll be good to change the ON_ERROR behavior at runtime, so users can set it to STOP when they're about to run a script via the \i command.

In psql this change is done via \set command. We don't have support for \set commands in pgcli. I was afraid that if we start supporting \set command, it'll open up a can of worms. But since we haven't received any issues regarding the \set command, I'm tempted to say, we can use the same command in pgcli, to maintain consistency with psql.

eg:

\set ON_ERROR_STOP on

amjith avatar Oct 14 '15 11:10 amjith

\set is also used for variable interpolation, like this:

dg=# \set foo 3.14159/2
dg=# \echo :foo
3.14159/2
dg=# select sin(:foo);
       sin
------------------
 0.99999999999912
(1 row)

Or is that the can of worms you mentioned?

darikg avatar Oct 14 '15 21:10 darikg

That's the can of worms I mentioned. Because now we're rewriting queries before we send them into psycopg2. Which could be as simple as a search and replace in a query, but we have to be careful not to replace things that are quoted and such.

amjith avatar Oct 15 '15 03:10 amjith