]> granicus.if.org Git - postgresql/commit - src/bin/psql/common.c
Add a \gexec command to psql for evaluation of computed queries.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Apr 2016 19:25:16 +0000 (15:25 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 4 Apr 2016 19:25:16 +0000 (15:25 -0400)
commit2bbe9112aec60abc2d3b4c39e75d0cbdcaaa45e1
treecd79ffca7612bdcd1ed77ff48b3f9e0a9be031b8
parent66229ac0040cf1e0f5b9d72271aa9feaf3b3a37e
Add a \gexec command to psql for evaluation of computed queries.

\gexec executes the just-entered query, like \g, but instead of printing
the results it takes each field as a SQL command to send to the server.
Computing a series of queries to be executed is a fairly common thing,
but up to now you always had to resort to kluges like writing the queries
to a file and then inputting the file.  Now it can be done with no
intermediate step.

The implementation is fairly straightforward except for its interaction
with FETCH_COUNT.  ExecQueryUsingCursor isn't capable of being called
recursively, and even if it were, its need to create a transaction
block interferes unpleasantly with the desired behavior of \gexec after
a failure of a generated query (i.e., that it can continue).  Therefore,
disable use of ExecQueryUsingCursor when doing the master \gexec query.
We can still apply it to individual generated queries, however, and there
might be some value in doing so.

While testing this feature's interaction with single-step mode, I (tgl) was
led to conclude that SendQuery needs to recognize SIGINT (cancel_pressed)
as a negative response to the single-step prompt.  Perhaps that's a
back-patchable bug fix, but for now I just included it here.

Corey Huinker, reviewed by Jim Nasby, Daniel Vérité, and myself
doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/command.c
src/bin/psql/common.c
src/bin/psql/help.c
src/bin/psql/settings.h
src/bin/psql/tab-complete.c
src/test/regress/expected/psql.out
src/test/regress/sql/psql.sql