Proposal: USING clause for DO statement - Mailing list pgsql-hackers

From Pavel Stehule
Subject Proposal: USING clause for DO statement
Date
Msg-id 162867790911210208m27c050eo858648c6577d0135@mail.gmail.com
Whole thread Raw
Responses Re: Proposal: USING clause for DO statement
Re: Proposal: USING clause for DO statement
List pgsql-hackers
Hello,

I am still thinking, about using DO statement from psql console. I am
missing any parametrisation. It could not be a problem. All pl have a
support for parameters, we have a libpq function PQexecParams - so we
need only some "USING" clause. I propose following syntax (and using
from client environments)

DO $$ body $$ USING expr [ ,expr [...]];

body should to have a unnamed parameters in syntax related to any PL.
I'll use plpgsql for this moment.

so some the most simply sample should look like:

DO $$
BEGIN RAISE NOTICE 'Hello, %', $1;
END
$$ USING 'World';

From psql:

\set message World
DO $$BEGIN RAISE NOTICE 'Hello, %', $1; END$$ USING :message;

From pgscript:

SET @message = 'World';
DO $$BEGIN RAISE NOTICE 'Hello, %', $1; END$$ USING @message;

From C

values[0] = "World";
result = PQexecParams(cn, "DO $$BEGIN RAISE NOTICE 'Hello, %', $1;
END;$$ USING $1",                                                1,
NULL,values,                                                 NULL, NULL,
0);
 

What do you thing about this proposal?

Regards
Pavel Stehule


pgsql-hackers by date:

Previous
From: Grzegorz Jaskiewicz
Date:
Subject: Re: DEFAULT of domain ignored in plpgsql (8.4.1)
Next
From: Pavel Stehule
Date:
Subject: Re: Proposal: USING clause for DO statement