diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-01-10 13:42:20 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2019-01-10 13:42:20 -0300 |
commit | 6260cc550b0e60052168518a0338e440b67cf24e (patch) | |
tree | b908db71586754d3c877cc69463c47f6acf29912 /src/fe_utils | |
parent | e1c1d5444e430375be9bc17366d17f1acd87ec0b (diff) | |
download | postgresql-6260cc550b0e60052168518a0338e440b67cf24e.tar.gz postgresql-6260cc550b0e60052168518a0338e440b67cf24e.zip |
pgbench: add \cset and \gset commands
These commands allow assignment of values produced by queries to pgbench
variables, where they can be used by further commands. \gset terminates
a command sequence (just like a bare semicolon); \cset separates
multiple queries in a compound command, like an escaped semicolon (\;).
A prefix can be provided to the \-command and is prepended to the name
of each output column to produce the final variable name.
This feature allows pgbench scripts to react meaningfully to the actual
database contents, allowing more powerful benchmarks to be written.
Authors: Fabien Coelho, Álvaro Herrera
Reviewed-by: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
Reviewed-by: Stephen Frost <sfrost@snowman.net>
Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Tatsuo Ishii <ishii@sraoss.co.jp>
Reviewed-by: Rafia Sabih <rafia.sabih@enterprisedb.com>
Discussion: https://postgr.es/m/alpine.DEB.2.20.1607091005330.3412@sto
Diffstat (limited to 'src/fe_utils')
-rw-r--r-- | src/fe_utils/psqlscan.l | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l index 9ea32c319f1..321744cddbb 100644 --- a/src/fe_utils/psqlscan.l +++ b/src/fe_utils/psqlscan.l @@ -693,8 +693,15 @@ other . * substitution. We want these before {self}, also. */ -"\\"[;:] { - /* Force a semicolon or colon into the query buffer */ +"\\"; { + /* Count semicolons in compound commands */ + cur_state->escaped_semicolons++; + /* Force a semicolon into the query buffer */ + psqlscan_emit(cur_state, yytext + 1, 1); + } + +"\\": { + /* Force a colon into the query buffer */ psqlscan_emit(cur_state, yytext + 1, 1); } @@ -1065,6 +1072,9 @@ psql_scan(PsqlScanState state, /* Set current output target */ state->output_buf = query_buf; + /* Reset number of escaped semicolons seen */ + state->escaped_semicolons = 0; + /* Set input source */ if (state->buffer_stack != NULL) yy_switch_to_buffer(state->buffer_stack->buf, state->scanner); @@ -1209,6 +1219,16 @@ psql_scan_reset(PsqlScanState state) } /* + * Return the number of escaped semicolons in the lexed string seen by the + * previous psql_scan call. + */ +int +psql_scan_get_escaped_semicolons(PsqlScanState state) +{ + return state->escaped_semicolons; +} + +/* * Reselect this lexer (psqlscan.l) after using another one. * * Currently and for foreseeable uses, it's sufficient to reset to INITIAL |