Re: Rethinking plpgsql's assignment implementation
Pavel Stehule <pavel.stehule@gmail.com>
From: Pavel Stehule <pavel.stehule@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Chapman Flack <chap@anastigmatix.net>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Dmitry Dolgov <9erthalion6@gmail.com>
Date: 2021-01-20T08:43:09Z
Lists: pgsql-hackers
út 19. 1. 2021 v 19:21 odesílatel Pavel Stehule <pavel.stehule@gmail.com>
napsal:
> Hi
>
> Now, I am testing subscribing on the jsonb feature, and I found one issue,
> that is not supported by parser.
>
> When the target is scalar, then all is ok. But we can have a plpgsql array
> of jsonb values.
>
> postgres=# do $$
> declare j jsonb[];
> begin
> j[1] = '{"b":"Ahoj"}';
> raise notice '%', j;
> raise notice '%', (j[1])['b'];
> end
> $$;
> NOTICE: {"{\"b\": \"Ahoj\"}"}
> NOTICE: "Ahoj"
> DO
>
> Parenthesis work well in expressions, but are not supported on the left
> side of assignment.
>
> postgres=# do $$
> declare j jsonb[];
> begin
> (j[1])['b'] = '"Ahoj"';
> raise notice '%', j;
> raise notice '%', j[1]['b'];
> end
> $$;
> ERROR: syntax error at or near "("
> LINE 4: (j[1])['b'] = '"Ahoj"';
> ^
>
Assignment for nesting composite types is working better - although there
is some inconsistency too:
create type t_inner as (x int, y int);
create type t_outer as (a t_inner, b t_inner);
do $$
declare v t_outer;
begin
v.a.x := 10; -- parenthesis not allowed here, but not required
raise notice '%', v;
raise notice '%', (v).a.x; -- parenthesis are required here
end;
$$;
Regards
Pavel
> Regards
>
> Pavel
>
>
>
Commits
-
Rethink the "read/write parameter" mechanism in pl/pgsql.
- 1c1cbe279b3c 14.0 landed
-
Remove PLPGSQL_DTYPE_ARRAYELEM datum type within pl/pgsql.
- 1788828d3351 14.0 landed
-
Re-implement pl/pgsql's expression and assignment parsing.
- c9d5298485b7 14.0 landed
-
Add the ability for the core grammar to have more than one parse target.
- 844fe9f159a9 14.0 landed
-
Support subscripting of arbitrary types, not only arrays.
- c7aba7c14efd 14.0 cited
-
Improve handling of array elements as getdiag_targets and cursor_variables.
- 55caaaeba877 10.0 cited