summaryrefslogtreecommitdiff
path: root/src/bin/psql/t/001_basic.pl
diff options
context:
space:
mode:
authorDaniel Gustafsson <dgustafsson@postgresql.org>2025-03-25 17:53:33 +0100
committerDaniel Gustafsson <dgustafsson@postgresql.org>2025-03-25 17:53:33 +0100
commit1a759c83278fcdae11ee5da8318b646b9d47129c (patch)
tree6b61dad74bd7337ac9c950bb5343ee18c3915caa /src/bin/psql/t/001_basic.pl
parenta19db082749662a933d0bf72722982b1ee2c4725 (diff)
psql: Make default \watch interval configurable
The default interval for \watch to wait between executing queries, when executed without a specified interval, was hardcoded to two seconds. This adds the new variable WATCH_INTERVAL which is used to set the default interval, making it configurable for the user. This makes \watch the first command which has a user configurable default setting. Author: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Kirill Reshke <reshkekirill@gmail.com> Reviewed-by: Masahiro Ikeda <ikedamsh@oss.nttdata.com> Reviewed-by: Laurenz Albe <laurenz.albe@cybertec.at> Reviewed-by: Greg Sabino Mullane <htamfids@gmail.com> Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com> Discussion: https://postgr.es/m/B2FD26B4-8F64-4552-A603-5CC3DF1C7103@yesql.se
Diffstat (limited to 'src/bin/psql/t/001_basic.pl')
-rw-r--r--src/bin/psql/t/001_basic.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/bin/psql/t/001_basic.pl b/src/bin/psql/t/001_basic.pl
index dca34ac975a..7192d96049d 100644
--- a/src/bin/psql/t/001_basic.pl
+++ b/src/bin/psql/t/001_basic.pl
@@ -375,6 +375,12 @@ psql_like(
$node, sprintf('SELECT 1 \watch c=3 i=%g', 0.0001),
qr/1\n1\n1/, '\watch with 3 iterations, interval of 0.0001');
+# Test zero interval
+psql_like(
+ $node, '\set WATCH_INTERVAL 0
+SELECT 1 \watch c=3',
+ qr/1\n1\n1/, '\watch with 3 iterations, interval of 0');
+
# Check \watch minimum row count
psql_fails_like(
$node,
@@ -426,6 +432,24 @@ psql_fails_like(
qr/iteration count is specified more than once/,
'\watch, iteration count is specified more than once');
+# Check WATCH_INTERVAL
+psql_like(
+ $node,
+ '\echo :WATCH_INTERVAL
+\set WATCH_INTERVAL 0.001
+\echo :WATCH_INTERVAL
+\unset WATCH_INTERVAL
+\echo :WATCH_INTERVAL',
+ qr/^2$
+^0.001$
+^2$/m,
+ 'WATCH_INTERVAL variable is set and updated');
+psql_fails_like(
+ $node,
+ '\set WATCH_INTERVAL 1e500',
+ qr/is out of range/,
+ 'WATCH_INTERVAL variable is out of range');
+
# Test \g output piped into a program.
# The program is perl -pe '' to simply copy the input to the output.
my $g_file = "$tempdir/g_file_1.out";