Re[2]: [HACKERS] Execute ignoring cursor? - Mailing list pgsql-hackers

From nummervet nummervet
Subject Re[2]: [HACKERS] Execute ignoring cursor?
Date
Msg-id 1460126801.315102444@f315.i.mail.ru
Whole thread Raw
In response to Re: Execute ignoring cursor?  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: Execute ignoring cursor?  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers
That didn't work for me:

ERROR:  syntax error at or near "$"
LINE 1: ...ibute_id, set_id ) (select $."151", '...


Пятница, 8 апреля 2016, 17:25 +03:00 от Pavel Stehule <pavel.stehule@gmail.com>:

Hi

2016-04-08 16:17 GMT+02:00 nummervet nummervet <nummervet@mail.ru>:
Hello. Didn't find dedicated plpgsql list, so decided to post question here.
I am trying to create a  function that will pick up some values from cursor and execute them as a dynamic query.
However, once i use EXECUTE, its seems to be ignoring the existence of cursor and try to pick up values from table.
Basically:

insert into mytable ( value, attribute_id, set_id ) (select rec."151", '201', '1')

works, but

execute 'insert into mytable ( value, attribute_id, set_id ) (select rec."151", ''201'', ''1'')'

Dynamic queries are executed in own space and there are not direct access to plpgsql variables.

please, try: execute 'insert into mytable ( value, attribute_id, set_id ) (select $1."151", ''201'', ''1'')' using rec;

Regards

Pavel Stehule
 

fails with

ERROR:  missing FROM-clause entry for table "rec"
LINE 1: ...ibute_id, set_id ) (select rec."151",...

Is there any way around it? Or should i just give up and do it some other way?



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: skink vs. phrase full text search
Next
From: Peter Eisentraut
Date:
Subject: Re: pam auth - add rhost item