Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 91287b5

Browse files
committed
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
1 parent 658fc6c commit 91287b5

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/test/regress/expected/psql.out

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ SELECT $1, $2 \parse stmt3
141141
ERROR: there is no parameter $1
142142
LINE 1: SELECT $1, $2
143143
^
144+
-- Last \bind_named wins
145+
\bind_named stmt2 'foo' \bind_named stmt3 'foo2' 'bar2' \g
146+
?column? | ?column?
147+
----------+----------
148+
foo2 | bar2
149+
(1 row)
150+
151+
-- Multiple \g calls mean multiple executions
152+
\bind_named stmt2 'foo3' \g \bind_named stmt3 'foo4' 'bar4' \g
153+
?column?
154+
----------
155+
foo3
156+
(1 row)
157+
158+
?column? | ?column?
159+
----------+----------
160+
foo4 | bar4
161+
(1 row)
162+
144163
-- \close (extended query protocol)
145164
\close
146165
\close: missing required argument
@@ -173,6 +192,25 @@ SELECT $1, $2 \bind 'foo' 'bar' \g
173192
foo | bar
174193
(1 row)
175194

195+
-- last \bind wins
196+
select $1::int as col \bind 'foo' \bind 2 \g
197+
col
198+
-----
199+
2
200+
(1 row)
201+
202+
-- Multiple \g calls mean multiple executions
203+
select $1::int as col \bind 1 \g \bind 2 \g
204+
col
205+
-----
206+
1
207+
(1 row)
208+
209+
col
210+
-----
211+
2
212+
(1 row)
213+
176214
-- errors
177215
-- parse error
178216
SELECT foo \bind \g

src/test/regress/sql/psql.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ SELECT $1, $2 \parse stmt3
6363
\bind_named stmt4
6464
\bind_named
6565
\g
66+
-- Last \bind_named wins
67+
\bind_named stmt2 'foo' \bind_named stmt3 'foo2' 'bar2' \g
68+
-- Multiple \g calls mean multiple executions
69+
\bind_named stmt2 'foo3' \g \bind_named stmt3 'foo4' 'bar4' \g
6670

6771
-- \close (extended query protocol)
6872
\close
@@ -76,6 +80,11 @@ SELECT 1 \bind \g
7680
SELECT $1 \bind 'foo' \g
7781
SELECT $1, $2 \bind 'foo' 'bar' \g
7882

83+
-- last \bind wins
84+
select $1::int as col \bind 'foo' \bind 2 \g
85+
-- Multiple \g calls mean multiple executions
86+
select $1::int as col \bind 1 \g \bind 2 \g
87+
7988
-- errors
8089
-- parse error
8190
SELECT foo \bind \g

0 commit comments

Comments
 (0)