summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2024-09-19 23:59:20 +0000
committerMichael Paquier2024-09-19 23:59:20 +0000
commit91287b5f5da324ac24678f556962e1b95e52240c (patch)
tree98f487c95d54310722ab402e6d58a8cc01958784
parent658fc6c6af4fa209af6ddadc0182cdb69e2b70ae (diff)
psql: Add tests for repeated calls of \bind[_named]
The implementation assumes that on multiple calls of these meta-commands the last one wins. Multiple \g calls in-between mean multiple executions. There were no tests to check these properties, hence let's add something. Author: Jelte Fennema-Nio, Michael Paquier Discussion: https://postgr.es/m/CAGECzQSTE7CoM=Gst56Xj8pOvjaPr09+7jjtWqTC40pGETyAuA@mail.gmail.com
-rw-r--r--src/test/regress/expected/psql.out38
-rw-r--r--src/test/regress/sql/psql.sql9
2 files changed, 47 insertions, 0 deletions
diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index cf040fbd803..3819bf5e254 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -141,6 +141,25 @@ SELECT $1, $2 \parse stmt3
ERROR: there is no parameter $1
LINE 1: SELECT $1, $2
^
+-- Last \bind_named wins
+\bind_named stmt2 'foo' \bind_named stmt3 'foo2' 'bar2' \g
+ ?column? | ?column?
+----------+----------
+ foo2 | bar2
+(1 row)
+
+-- Multiple \g calls mean multiple executions
+\bind_named stmt2 'foo3' \g \bind_named stmt3 'foo4' 'bar4' \g
+ ?column?
+----------
+ foo3
+(1 row)
+
+ ?column? | ?column?
+----------+----------
+ foo4 | bar4
+(1 row)
+
-- \close (extended query protocol)
\close
\close: missing required argument
@@ -173,6 +192,25 @@ SELECT $1, $2 \bind 'foo' 'bar' \g
foo | bar
(1 row)
+-- last \bind wins
+select $1::int as col \bind 'foo' \bind 2 \g
+ col
+-----
+ 2
+(1 row)
+
+-- Multiple \g calls mean multiple executions
+select $1::int as col \bind 1 \g \bind 2 \g
+ col
+-----
+ 1
+(1 row)
+
+ col
+-----
+ 2
+(1 row)
+
-- errors
-- parse error
SELECT foo \bind \g
diff --git a/src/test/regress/sql/psql.sql b/src/test/regress/sql/psql.sql
index 8de90c805c0..c5021fc0b13 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -63,6 +63,10 @@ SELECT $1, $2 \parse stmt3
\bind_named stmt4
\bind_named
\g
+-- Last \bind_named wins
+\bind_named stmt2 'foo' \bind_named stmt3 'foo2' 'bar2' \g
+-- Multiple \g calls mean multiple executions
+\bind_named stmt2 'foo3' \g \bind_named stmt3 'foo4' 'bar4' \g
-- \close (extended query protocol)
\close
@@ -76,6 +80,11 @@ SELECT 1 \bind \g
SELECT $1 \bind 'foo' \g
SELECT $1, $2 \bind 'foo' 'bar' \g
+-- last \bind wins
+select $1::int as col \bind 'foo' \bind 2 \g
+-- Multiple \g calls mean multiple executions
+select $1::int as col \bind 1 \g \bind 2 \g
+
-- errors
-- parse error
SELECT foo \bind \g