-- \getresults immediately returns if there is no result to fetch.
\startpipeline
\getresults SELECT $1 \bind 2 \sendpipeline
\getresults
\flushrequest
\endpipeline
\getresults
-- \syncpipeline count as one command to fetch for \getresults.
\startpipeline
\syncpipeline
\syncpipeline SELECT $1 \bind 1 \sendpipeline
\flushrequest
\getresults 2
\getresults 1
\endpipeline
-- \getresults 0 should get all the results.
\startpipeline SELECT $1 \bind 1 \sendpipeline SELECT $1 \bind 2 \sendpipeline SELECT $1 \bind 3 \sendpipeline
\syncpipeline
\getresults 0
\endpipeline
-- -- Pipeline errors --
-- \endpipeline outside of pipeline should fail
\endpipeline
-- After an aborted pipeline, commands after a \syncpipeline should be -- displayed.
\startpipeline SELECT $1 \bind \sendpipeline
\syncpipeline SELECT $1 \bind 1 \sendpipeline
\endpipeline
-- For an incorrect number of parameters, the pipeline is aborted and -- the following queries will not be executed.
\startpipeline SELECT \bind 'val1' \sendpipeline SELECT $1 \bind 'val1' \sendpipeline
\endpipeline
-- Using a semicolon with a parameter triggers an error and aborts -- the pipeline.
\startpipeline SELECT $1; SELECT1;
\endpipeline
-- An explicit transaction with an error needs to be rollbacked after -- the pipeline.
\startpipeline
BEGIN \bind \sendpipeline INSERTINTO psql_pipeline VALUES ($1) \bind 1 \sendpipeline
ROLLBACK \bind \sendpipeline
\endpipeline
ROLLBACK;
-- \watch is not allowed in a pipeline.
\startpipeline SELECT \bind \sendpipeline
\watch 1
\endpipeline
-- \gdesc should fail as synchronous commands are not allowed in a pipeline, -- and the pipeline should still be usable.
\startpipeline SELECT $1 \bind 1 \gdesc SELECT $1 \bind 1 \sendpipeline
\endpipeline
-- \gset is not allowed in a pipeline, pipeline should still be usable.
\startpipeline SELECT $1as i, $2as j \parse '' SELECT $1as k, $2as l \parse 'second'
\bind_named ''12 \gset
\bind_named second 12 \gset pref02_ \echo :pref02_i :pref02_j
\bind_named ''12 \sendpipeline
\endpipeline
-- \g and \gx are not allowed, pipeline should still be usable.
\startpipeline SELECT $1 \bind 1 \g SELECT $1 \bind 1 \g (format=unaligned tuples_only=on) SELECT $1 \bind 1 \gx SELECT $1 \bind 1 \gx (format=unaligned tuples_only=on)
\reset SELECT $1 \bind 1 \sendpipeline
\endpipeline
-- \g and \gx warnings should be emitted in an aborted pipeline, with -- pipeline still usable.
\startpipeline SELECT $1 \bind \sendpipeline
\flushrequest
\getresults SELECT $1 \bind 1 \g SELECT $1 \bind 1 \gx
\endpipeline
-- \sendpipeline is not allowed outside of a pipeline
\sendpipeline SELECT $1 \bind 1 \sendpipeline
\reset
-- \sendpipeline is not allowed if not preceded by \bind or \bind_named
\startpipeline
\sendpipeline SELECT1 \sendpipeline
\endpipeline
-- \gexec is not allowed, pipeline should still be usable.
\startpipeline SELECT'INSERT INTO psql_pipeline(a) SELECT generate_series(1, 10)' \parse 'insert_stmt'
\bind_named insert_stmt \gexec
\bind_named insert_stmt \sendpipeline SELECT COUNT(*) FROM psql_pipeline \bind \sendpipeline
\endpipeline
-- After an error, pipeline is aborted and requires \syncpipeline to be -- reusable.
\startpipeline SELECT $1 \bind \sendpipeline SELECT $1 \bind 1 \sendpipeline SELECT $1 \parse a
\bind_named a 1 \sendpipeline
\close_prepared a
\flushrequest
\getresults -- Pipeline is aborted. SELECT $1 \bind 1 \sendpipeline SELECT $1 \parse a
\bind_named a 1 \sendpipeline
\close_prepared a -- Sync allows pipeline to recover.
\syncpipeline
\getresults SELECT $1 \bind 1 \sendpipeline SELECT $1 \parse a
\bind_named a 1 \sendpipeline
\close_prepared a
\flushrequest
\getresults
\endpipeline
-- In an aborted pipeline, \getresults 1 aborts commands one at a time.
\startpipeline SELECT $1 \bind \sendpipeline SELECT $1 \bind 1 \sendpipeline SELECT $1 \parse a
\bind_named a 1 \sendpipeline
\syncpipeline
\getresults 1
\getresults 1
\getresults 1
\getresults 1
\getresults 1
\endpipeline
-- Test chunked results with an aborted pipeline.
\startpipeline
\set FETCH_COUNT 10 SELECT $1 \bind \sendpipeline
\flushrequest
\getresults SELECT $1 \bind \sendpipeline
\endpipeline
\unset FETCH_COUNT
-- \getresults returns an error when an incorrect number is provided.
\startpipeline
\getresults -1
\endpipeline
-- \getresults when there is no result should not impact the next -- query executed.
\getresults 1 select1;
-- Error messages accumulate and are repeated.
\startpipeline SELECT1 \bind \sendpipeline
\gdesc
\gdesc
\endpipeline
-- -- Pipelines and transaction blocks --
-- SET LOCAL will issue a warning when modifying a GUC outside of a -- transaction block. The change will still be valid as a pipeline -- runs within an implicit transaction block. Sending a sync will -- commit the implicit transaction block. The first command after a -- sync will not be seen as belonging to a pipeline.
\startpipeline SET LOCAL statement_timeout='1h' \bind \sendpipeline SHOW statement_timeout \bind \sendpipeline
\syncpipeline SHOW statement_timeout \bind \sendpipeline SET LOCAL statement_timeout='2h' \bind \sendpipeline SHOW statement_timeout \bind \sendpipeline
\endpipeline
-- REINDEX CONCURRENTLY fails if not the first command in a pipeline.
\startpipeline SELECT $1 \bind 1 \sendpipeline
REINDEX TABLE CONCURRENTLY psql_pipeline \bind \sendpipeline SELECT $1 \bind 2 \sendpipeline
\endpipeline
-- REINDEX CONCURRENTLY works if it is the first command in a pipeline.
\startpipeline
REINDEX TABLE CONCURRENTLY psql_pipeline \bind \sendpipeline SELECT $1 \bind 2 \sendpipeline
\endpipeline
-- Subtransactions are not allowed in a pipeline.
\startpipeline
SAVEPOINT a \bind \sendpipeline SELECT $1 \bind 1 \sendpipeline
ROLLBACK TO SAVEPOINT a \bind \sendpipeline SELECT $1 \bind 2 \sendpipeline
\endpipeline
-- LOCK fails as the first command in a pipeline, as not seen in an -- implicit transaction block.
\startpipeline LOCK psql_pipeline \bind \sendpipeline SELECT $1 \bind 2 \sendpipeline
\endpipeline
-- LOCK succeeds as it is not the first command in a pipeline, -- seen in an implicit transaction block.
\startpipeline SELECT $1 \bind 1 \sendpipeline LOCK psql_pipeline \bind \sendpipeline SELECT $1 \bind 2 \sendpipeline
\endpipeline
-- VACUUM works as the first command in a pipeline.
\startpipeline
VACUUM psql_pipeline \bind \sendpipeline
\endpipeline
-- VACUUM fails when not the first command in a pipeline.
\startpipeline SELECT1 \bind \sendpipeline
VACUUM psql_pipeline \bind \sendpipeline
\endpipeline
-- VACUUM works after a \syncpipeline.
\startpipeline SELECT1 \bind \sendpipeline
\syncpipeline
VACUUM psql_pipeline \bind \sendpipeline
\endpipeline
-- Clean up DROPTABLE psql_pipeline;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.