By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,935 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,935 IT Pros & Developers. It's quick & easy.

plpgsql update cursor where current of with dynamic query

P: 48
plpgsql (postgresql 8.3 but I can upgrade)

I can open a cursor with a dynamic query (table / column variable) :
-open cursor for execute '...' ;
But if I want do updates...
- execute 'update ...' where current of cursor ??
Mmm I don't find the way.

Another approach :

-execute 'declare cursor ...' +with hold -for update :(
-execute 'update ... where current of cursor'
But how can I get the reference of the cursor into the function context?
I remember something like synchronizing contexts, but this time I couldn't find nothing about it.

The classical approach :

-for i in execute '...' loop
But to perform an update, I must apply a where clause with its performance penalty, I get no advantage on the current loop.

What do you think about this?
Oct 16 '09 #1
Share this Question
Share on Google+
1 Reply

P: 48
I got an answer in freenode irc, if someone is interested :
A refcursor variable is a string that globaly references a portal/container of the query that stores the cursor. So :
execute 'update '||table_name||' set var=val where current of '||quote_ident(cursor::text) ;
Oct 17 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.