On Thu, 19 Sept 2024 at 09:30, Michael Paquier <mich...@paquier.xyz> wrote:
> Issuing an error if there is a state does not sound like a good idea
> at this stage because it would suddenly break scripts that expect
> multiple commands of \bind to prioritize the last one.

Seems like a good idea to add a simple test for that behaviour then.
See attached.

On Thu, 19 Sept 2024 at 09:30, Michael Paquier <mich...@paquier.xyz> wrote:
>
> On Wed, Sep 18, 2024 at 06:08:54PM +0900, Michael Paquier wrote:
> > On Wed, Sep 18, 2024 at 09:42:43AM +0200, Anthonin Bonnefoy wrote:
> >> I've joined a patch to clean the psql extended state at the start of
> >> every extended protocol backslash command, freeing the allocated
> >> variables and resetting the send_mode. Another possible approach would
> >> be to return an error when there's already an existing state instead
> >> of overwriting it.
> >
> > I'll double-check all that tomorrow, but you have looks like it is
> > going in the right direction.
>
> And done down to v16, with one logic for HEAD and something simpler
> for \bind in v16 and v17.
>
> Issuing an error if there is a state does not sound like a good idea
> at this stage because it would suddenly break scripts that expect
> multiple commands of \bind to prioritize the last one.  If that was
> something only on HEAD, I would have considered that as a serious
> option, but not with v16 in mind for \bind.
> --
> Michael
From 20637d0fdfb08ed7e79a241b82b1d4f9f9f34d8c Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <github-t...@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

Reply via email to