mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
Allow DECLARE CURSOR to take parameters from the portal in which it is
executed. Previously, the DECLARE would succeed but subsequent FETCHes would fail since the parameter values supplied to DECLARE were not propagated to the portal created for the cursor. In support of this, add type Oids to ParamListInfo entries, which seems like a good idea anyway since code that extracts a value can double-check that it got the type of value it was expecting. Oliver Jowett, with minor editorialization by Tom Lane.
This commit is contained in:
@@ -738,3 +738,38 @@ ROLLBACK;
|
||||
-- should fail
|
||||
FETCH FROM foo26;
|
||||
ERROR: cursor "foo26" does not exist
|
||||
--
|
||||
-- Parameterized DECLARE needs to insert param values into the cursor portal
|
||||
--
|
||||
BEGIN;
|
||||
CREATE FUNCTION declares_cursor(text)
|
||||
RETURNS void
|
||||
AS 'DECLARE c CURSOR FOR SELECT stringu1 FROM tenk1 WHERE stringu1 LIKE $1;'
|
||||
LANGUAGE 'sql';
|
||||
SELECT declares_cursor('AB%');
|
||||
declares_cursor
|
||||
-----------------
|
||||
|
||||
(1 row)
|
||||
|
||||
FETCH ALL FROM c;
|
||||
stringu1
|
||||
----------
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
ABAAAA
|
||||
(15 rows)
|
||||
|
||||
ROLLBACK;
|
||||
|
||||
@@ -218,3 +218,20 @@ ROLLBACK;
|
||||
|
||||
-- should fail
|
||||
FETCH FROM foo26;
|
||||
|
||||
--
|
||||
-- Parameterized DECLARE needs to insert param values into the cursor portal
|
||||
--
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE FUNCTION declares_cursor(text)
|
||||
RETURNS void
|
||||
AS 'DECLARE c CURSOR FOR SELECT stringu1 FROM tenk1 WHERE stringu1 LIKE $1;'
|
||||
LANGUAGE 'sql';
|
||||
|
||||
SELECT declares_cursor('AB%');
|
||||
|
||||
FETCH ALL FROM c;
|
||||
|
||||
ROLLBACK;
|
||||
|
||||
Reference in New Issue
Block a user