summaryrefslogtreecommitdiff
path: root/src/bin/psql/t/001_basic.pl
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2023-08-29 11:30:11 +0200
committerDaniel Gustafsson <dgustafsson@postgresql.org>2023-08-29 11:30:11 +0200
commitf347ec76e2a227e5c5b5065cce7adad16d58d209 (patch)
tree0d03e7a4caa335a0b9ae014299ccabbac8486c3f /src/bin/psql/t/001_basic.pl
parent95fff2abee66c16ca3609b3c1638cbd553730a90 (diff)
Allow \watch queries to stop on minimum rows returned
When running a repeat query with \watch in psql, it can be helpful to be able to stop the watch process when the query no longer returns the expected amount of rows. An example would be to watch for the presence of a certain event in pg_stat_activity and stopping when the event is no longer present, or to watch an index creation and stop when the index is created. This adds a min_rows=MIN parameter to \watch which can be set to a non-negative integer, and the watch query will stop executing when it returns less than MIN rows. Author: Greg Sabino Mullane <htamfids@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Daniel Gustafsson <daniel@yesql.se> Discussion: https://postgr.es/m/CAKAnmmKStATuddYxP71L+p0DHtp9Rvjze3XRoy0Dyw67VQ45UA@mail.gmail.com
Diffstat (limited to 'src/bin/psql/t/001_basic.pl')
-rw-r--r--src/bin/psql/t/001_basic.pl23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index 9ac27db2120..5398a1dbf3d 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -355,6 +355,29 @@ psql_like(
psql_like($node, sprintf('SELECT 1 \watch c=3 i=%g', 0.01),
qr/1\n1\n1/, '\watch with 3 iterations');
+# Check \watch minimum row count
+psql_fails_like(
+ $node,
+ 'SELECT 3 \watch m=x',
+ qr/incorrect minimum row count/,
+ '\watch, invalid minimum row setting');
+
+psql_fails_like(
+ $node,
+ 'SELECT 3 \watch m=1 min_rows=2',
+ qr/minimum row count specified more than once/,
+ '\watch, minimum rows is specified more than once');
+
+psql_like(
+ $node,
+ q{with x as (
+ select now()-backend_start AS howlong
+ from pg_stat_activity
+ where pid = pg_backend_pid()
+ ) select 123 from x where howlong < '2 seconds' \watch i=0.5 m=2},
+ qr/^123$/,
+ '\watch, 2 minimum rows');
+
# Check \watch errors
psql_fails_like(
$node,