From f09d9746b1ab8d3b55226488744c1e1598d25bdf Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Wed, 18 Dec 2024 21:47:33 -0800 Subject: [PATCH] sql: allow CLOSE CURSOR in read-only txns This is allowed in PG, so we now will allow this too. The fix is similar to what we did for DECLARE and FETCH in 50a799953f27e672e08006a791d32154f7221641. Release note (bug fix): CLOSE CURSOR statements are now allowed in read-only transactions, similat to Postgres. The bug has been present since at least 23.1 version. --- pkg/sql/logictest/testdata/logic_test/txn | 5 ++++- pkg/sql/sem/tree/stmt.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/txn b/pkg/sql/logictest/testdata/logic_test/txn index b9069f0a6a94..85063ed9feb3 100644 --- a/pkg/sql/logictest/testdata/logic_test/txn +++ b/pkg/sql/logictest/testdata/logic_test/txn @@ -1520,13 +1520,16 @@ SET SESSION AUTHORIZATION DEFAULT statement ok BEGIN -# DECLARE and FETCH CURSOR should work in a read-only txn. +# DECLARE, FETCH, and CLOSE CURSOR should work in a read-only txn. statement ok DECLARE foo CURSOR FOR SELECT 1 statement ok FETCH 1 foo +statement ok +CLOSE foo + statement ok COMMIT diff --git a/pkg/sql/sem/tree/stmt.go b/pkg/sql/sem/tree/stmt.go index a5cdde453f9d..47bed5989f09 100644 --- a/pkg/sql/sem/tree/stmt.go +++ b/pkg/sql/sem/tree/stmt.go @@ -768,7 +768,7 @@ func (*CannedOptPlan) StatementTag() string { return "PREPARE AS OPT PLAN" } func (*CloseCursor) StatementReturnType() StatementReturnType { return Ack } // StatementType implements the Statement interface. -func (*CloseCursor) StatementType() StatementType { return TypeDCL } +func (*CloseCursor) StatementType() StatementType { return TypeDML } // StatementTag returns a short string identifying the type of statement. func (*CloseCursor) StatementTag() string { return "CLOSE" }