Re: pass open cursor via USING in execute staement

From: Kirk Wolak <wolakk(at)gmail(dot)com>
To: domenico(dot)l76(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: pass open cursor via USING in execute staement
Date: 2023-06-06 19:48:42
Message-ID: CACLU5mQUJiCJqzpOoXRWRUeVS0bGyK2ogHDqTQXuHsdBLf4CuQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Thu, Jun 1, 2023 at 9:32 AM PG Doc comments form <noreply(at)postgresql(dot)org>
wrote:

> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/15/plpgsql-statements.html
> Description:
>
> Should be documented if this statement is allowed or not (if not, maybe set
> as desired feature :-) )
>
> EXECUTE format('update %I set col1=$1, col2=now() WHERE current of $3',
> tabname)
> USING myVal, myOpenCursor;
>

Well, you can handle this by naming the cursor specifically, based on the
table that should be updated.
Then using the name of myOpenCursor.

and you use a refcursor variable to pass them around.
You name them like this, before opening them:
cCursor := 'my_cursor_update_table3';

Now usually the name matches the incoming variable name. You are going
to have to play with this.
Later in your code, you can test the value of the cursor name by simply
doing:
RAISE NOTICE 'Cursor Name: %', cCursor;

So you can copy it to a variable, and compare it. Then determine the
table to apply the update to.

That's the best I can come up with...

Kirk Out!

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message vignesh C 2023-06-07 10:39:47 Re: clarifying trigger/rule behavior on logical replication subscribers
Previous Message David G. Johnston 2023-06-06 16:46:06 Re: bpchar datatype is not equal to character(1) data type