From 20637d0fdfb08ed7e79a241b82b1d4f9f9f34d8c Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <github-tech@jeltef.nl>
Date: Thu, 19 Sep 2024 10:50:53 +0200
Subject: [PATCH v1] psql: Add test for repeated \bind calls

---
 src/test/regress/expected/psql.out | 19 +++++++++++++++++++
 src/test/regress/sql/psql.sql      |  5 +++++
 2 files changed, 24 insertions(+)

diff --git a/src/test/regress/expected/psql.out b/src/test/regress/expected/psql.out
index cf040fbd80..83a51c9682 100644
--- a/src/test/regress/expected/psql.out
+++ b/src/test/regress/expected/psql.out
@@ -173,6 +173,25 @@ SELECT $1, $2 \bind 'foo' 'bar' \g
  foo      | bar
 (1 row)
 
+-- second bind overwrites first
+select $1 as col \bind 1 \bind 2 \g
+ col 
+-----
+ 2
+(1 row)
+
+-- unless there's a \g in between
+select $1 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 8de90c805c..b027e0eb7d 100644
--- a/src/test/regress/sql/psql.sql
+++ b/src/test/regress/sql/psql.sql
@@ -76,6 +76,11 @@ SELECT 1 \bind \g
 SELECT $1 \bind 'foo' \g
 SELECT $1, $2 \bind 'foo' 'bar' \g
 
+-- second bind overwrites first
+select $1 as col \bind 1 \bind 2 \g
+-- unless there's a \g in between
+select $1 as col \bind 1 \g \bind 2 \g
+
 -- errors
 -- parse error
 SELECT foo \bind \g
-- 
2.43.0

