Re: plpgsql - execute - cannot use a reference to record field - Mailing list pgsql-hackers

From Tom Lane
Subject Re: plpgsql - execute - cannot use a reference to record field
Date
Msg-id 16344.1555344445@sss.pgh.pa.us
Whole thread Raw
In response to plpgsql - execute - cannot use a reference to record field  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: plpgsql - execute - cannot use a reference to record field
List pgsql-hackers
Pavel Stehule <pavel.stehule@gmail.com> writes:
> Is there reason why following code should not to work?

> do $$
> declare r record; result int;
> begin
>   select 10 as a, 20 as b into r;
>   raise notice 'a: %', r.a;
>   execute 'select $1.a + $1.b' into result using r;
>   raise notice '%', result;
> end;
> $$

You can't select fields by name out of an unspecified record.
The EXECUTE'd query is not particularly different from

regression=# prepare foo(record) as select $1.a + $1.b;
psql: ERROR:  could not identify column "a" in record data type
LINE 1: prepare foo(record) as select $1.a + $1.b;
                                      ^

and surely you wouldn't expect that to work.
(The fact that either of the previous lines work is
thanks to plpgsql-specific hacking.)

            regards, tom lane



pgsql-hackers by date:

Previous
From: Dean Rasheed
Date:
Subject: Multivariate MCV lists -- pg_mcv_list_items() seems to be broken
Next
From: Ashwin Agrawal
Date:
Subject: Re: Zedstore - compressed in-core columnar storage