Re: [HACKERS] proposal - plpgsql: execute using into

Lists: pgsql-hackerspgsql-patches
From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: proposal - plpgsql: execute using into
Date: 2006-03-27 19:39:54
Message-ID: BAY20-F209756D26D9C0F8CE6001CF9D20@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hello

Current EXECUTE statemtn doesn't support other way for parametrisation than
concating strings. It works well but it's little bit unreadable. Oracle's
statement EXECUTE has positional replacement feature. It works similar our
RAISE statement (when position holder is %). EXECUTE position holder has
form :xxxx. xxxx has only symbolic value and isn't used for anything. Syntax
of enhanced statements is:

EXECUTE 'format string' USING expr_list

There are some problems about replacing string values in the SQL string.
Sometimes we have to enclose value between spaces or others symbols
(apostrophe or double apostrophe), sometimes not. Possible rules:
a) if position holder is inside string or identifier we don't enclose
value;
b) else numeric values are enclosed spaces and others (non regclass)
single apostrophes
c) regclass's values are enclosed douple apostrophes.

PL/pgSQL knows three dynamic statements. All will be enhanced.

Some examples:

EXECUTE 'SELECT :name||:sp||:surname' USING 'Pavel',' ','Stehule';
EXECUTE e'SELECT \':name :surname' USING 'Pavel','Stehule';
EXECUTE 'SELECT * FROM :tabname' USING 'xb'::regclass;
EXECUTE 'SELECT * FROM ":base:num" USING 'mytab',1;

You can test it. I sent patch to pg_patches.

I invite any comments

Pavel Stehule

_________________________________________________________________
Emotikony a pozadi programu MSN Messenger ozivi vasi konverzaci.
http://messenger.msn.cz/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal - plpgsql: execute using into
Date: 2006-03-27 21:09:36
Message-ID: 17359.1143493776@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

"Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com> writes:
> Current EXECUTE statemtn doesn't support other way for parametrisation than
> concating strings. It works well but it's little bit unreadable. Oracle's
> statement EXECUTE has positional replacement feature.
> ...
> There are some problems about replacing string values in the SQL string.

Doesn't the Oracle implementation already imply a solution to that?

The examples you give look to me like they are escaping problems waiting
to happen, especially in view of the upcoming change in default
backslash behavior, so this whole thing makes me feel pretty nervous.
I think we'd be best off to leave EXECUTE alone, at least until we've
converged to the point where almost nobody is using non-standard-compliant
strings.

regards, tom lane


From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal - plpgsql: execute using into
Date: 2006-03-28 13:01:55
Message-ID: BAY20-F155D9BBD738840E24AECCDF9D30@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

> > There are some problems about replacing string values in the SQL string.
>
>Doesn't the Oracle implementation already imply a solution to that?
>

I don't know. I didn't find any detail documentation about it. I don't know
what Oracle exactly do.

>I think we'd be best off to leave EXECUTE alone, at least until we've
>converged to the point where almost nobody is using non-standard-compliant
>strings.
>

Maybe, but patch have to solve SQL string and non SQL strings too

Regards
Pavel Stehule

_________________________________________________________________
Citite se osamele? Poznejte nekoho vyjmecneho diky Match.com.
http://www.msn.cz/


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal - plpgsql: execute using into
Date: 2006-04-21 23:53:43
Message-ID: 200604212353.k3LNrh804302@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Pavel Stehule wrote:
> > > There are some problems about replacing string values in the SQL string.
> >
> >Doesn't the Oracle implementation already imply a solution to that?
> >
>
> I don't know. I didn't find any detail documentation about it. I don't know
> what Oracle exactly do.
>
> >I think we'd be best off to leave EXECUTE alone, at least until we've
> >converged to the point where almost nobody is using non-standard-compliant
> >strings.
> >
>
> Maybe, but patch have to solve SQL string and non SQL strings too

Pavel, I am still confused what the USING clause is for, and you need to
research how Oracle handles it before we can add this. Would you
provide an example of its usage?

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [HACKERS] proposal - plpgsql: execute using into
Date: 2006-08-21 17:45:54
Message-ID: 200608211745.k7LHjsg03125@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Pavel Stehule wrote:
> > > There are some problems about replacing string values in the SQL string.
> >
> >Doesn't the Oracle implementation already imply a solution to that?
> >
>
> I don't know. I didn't find any detail documentation about it. I don't know
> what Oracle exactly do.

Oracle does use USING:

EXECUTE IMMEDIATE dynamic_string
[INTO {define_variable[, define_variable]... | record}]
[USING [IN | OUT | IN OUT] bind_argument
[, [IN | OUT | IN OUT] bind_argument]...]
[{RETURNING | RETURN} INTO bind_argument[, bind_argument]...];

so I think we are OK there.

> >I think we'd be best off to leave EXECUTE alone, at least until we've
> >converged to the point where almost nobody is using non-standard-compliant
> >strings.
> >
>
> Maybe, but patch have to solve SQL string and non SQL strings too

The only case I see you using it is for \:. What is the purpose of
that? Can't we use :: for a literal :?

I have attached the patch from March.

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
execute_using.dif text/x-diff 22.0 KB

From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: bruce(at)momjian(dot)us
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] proposal - plpgsql: execute using into
Date: 2006-08-21 19:56:55
Message-ID: BAY20-F15292EF5A41F8400B7DE9FF9410@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches

Hello,

This task can be better solved. There are some problems with strings, but
bigger problem is impossibility to pass nonscalar variables. What is
questions? Does Oracle allow variables on nonparam positions? If not, then I
see more elegant solution via preprocessed statements.

Best regards
Pavel Stehule

>
>Pavel Stehule wrote:
> > > > There are some problems about replacing string values in the SQL
>string.
> > >
> > >Doesn't the Oracle implementation already imply a solution to that?
> > >
> >
> > I don't know. I didn't find any detail documentation about it. I don't
>know
> > what Oracle exactly do.
>
>Oracle does use USING:
>
> EXECUTE IMMEDIATE dynamic_string
> [INTO {define_variable[, define_variable]... | record}]
> [USING [IN | OUT | IN OUT] bind_argument
> [, [IN | OUT | IN OUT] bind_argument]...]
> [{RETURNING | RETURN} INTO bind_argument[, bind_argument]...];
>
>so I think we are OK there.
>
> > >I think we'd be best off to leave EXECUTE alone, at least until we've
> > >converged to the point where almost nobody is using
>non-standard-compliant
> > >strings.
> > >
> >
> > Maybe, but patch have to solve SQL string and non SQL strings too
>
>The only case I see you using it is for \:. What is the purpose of
>that? Can't we use :: for a literal :?
>
>I have attached the patch from March.
>
>--
> Bruce Momjian bruce(at)momjian(dot)us
> EnterpriseDB http://www.enterprisedb.com
>
> + If your life is a hard drive, Christ can be your backup. +

><< execute_using.dif >>

>
>---------------------------(end of broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

_________________________________________________________________
Chcete sdilet sve obrazky a hudbu s prateli? http://messenger.msn.cz/


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Pavel Stehule <pavel(dot)stehule(at)hotmail(dot)com>
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-patches(at)postgresql(dot)org
Subject: Re: [HACKERS] proposal - plpgsql: execute using
Date: 2006-09-02 21:22:48
Message-ID: 200609022122.k82LMm306177@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers pgsql-patches


So the patch is being withdrawn by the author? OK.

---------------------------------------------------------------------------

Pavel Stehule wrote:
> Hello,
>
> This task can be better solved. There are some problems with strings, but
> bigger problem is impossibility to pass nonscalar variables. What is
> questions? Does Oracle allow variables on nonparam positions? If not, then I
> see more elegant solution via preprocessed statements.
>
> Best regards
> Pavel Stehule
>
> >
> >Pavel Stehule wrote:
> > > > > There are some problems about replacing string values in the SQL
> >string.
> > > >
> > > >Doesn't the Oracle implementation already imply a solution to that?
> > > >
> > >
> > > I don't know. I didn't find any detail documentation about it. I don't
> >know
> > > what Oracle exactly do.
> >
> >Oracle does use USING:
> >
> > EXECUTE IMMEDIATE dynamic_string
> > [INTO {define_variable[, define_variable]... | record}]
> > [USING [IN | OUT | IN OUT] bind_argument
> > [, [IN | OUT | IN OUT] bind_argument]...]
> > [{RETURNING | RETURN} INTO bind_argument[, bind_argument]...];
> >
> >so I think we are OK there.
> >
> > > >I think we'd be best off to leave EXECUTE alone, at least until we've
> > > >converged to the point where almost nobody is using
> >non-standard-compliant
> > > >strings.
> > > >
> > >
> > > Maybe, but patch have to solve SQL string and non SQL strings too
> >
> >The only case I see you using it is for \:. What is the purpose of
> >that? Can't we use :: for a literal :?
> >
> >I have attached the patch from March.
> >
> >--
> > Bruce Momjian bruce(at)momjian(dot)us
> > EnterpriseDB http://www.enterprisedb.com
> >
> > + If your life is a hard drive, Christ can be your backup. +
>
>
> ><< execute_using.dif >>
>
>
> >
> >---------------------------(end of broadcast)---------------------------
> >TIP 3: Have you checked our extensive FAQ?
> >
> > http://www.postgresql.org/docs/faq
>
> _________________________________________________________________
> Chcete sdilet sve obrazky a hudbu s prateli? http://messenger.msn.cz/
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

--
Bruce Momjian bruce(at)momjian(dot)us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +