mirror of
https://github.com/postgres/postgres.git
synced 2026-01-27 21:43:08 +03:00
Improve handling of array elements as getdiag_targets and cursor_variables.
There's no good reason why plpgsql's GET DIAGNOSTICS statement can't support an array element as target variable, since the execution code already uses the generic exec_assign_value() function to assign to it. Hence, refactor the grammar to allow that, by making getdiag_target depend on the assign_var production. Ideally we'd also let a cursor_variable expand to an element of a refcursor[] array, but that's substantially harder since those statements also have to handle bound-cursor-variable cases. For now, just make sure the reported error is sensible, ie "cursor variable must be a simple variable" not "variable must be of type cursor or refcursor". The latter was quite confusing from the user's viewpoint, since what he wrote satisfies the claimed restriction. Per bug #14463 from Zhou Digoal. Given the lack of previous complaints, I see no need for a back-patch. Discussion: https://postgr.es/m/20161213152548.14897.81245@wrigleys.postgresql.org
This commit is contained in:
@@ -3719,6 +3719,7 @@ drop function tftest(int);
|
||||
create or replace function rttest()
|
||||
returns setof int as $$
|
||||
declare rc int;
|
||||
rca int[];
|
||||
begin
|
||||
return query values(10),(20);
|
||||
get diagnostics rc = row_count;
|
||||
@@ -3727,11 +3728,12 @@ begin
|
||||
get diagnostics rc = row_count;
|
||||
raise notice '% %', found, rc;
|
||||
return query execute 'values(10),(20)';
|
||||
get diagnostics rc = row_count;
|
||||
raise notice '% %', found, rc;
|
||||
-- just for fun, let's use array elements as targets
|
||||
get diagnostics rca[1] = row_count;
|
||||
raise notice '% %', found, rca[1];
|
||||
return query execute 'select * from (values(10),(20)) f(a) where false';
|
||||
get diagnostics rc = row_count;
|
||||
raise notice '% %', found, rc;
|
||||
get diagnostics rca[2] = row_count;
|
||||
raise notice '% %', found, rca[2];
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user