Re: [PATCHES] V0.1 patch for TODO Item: SQL-language reference parameters by name.

2007-11-02 Thread Pavel Stehule
On 02/11/2007, Gevik Babakhani <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> > what about name's collision? Maybe is better use some prefix,
> > like $ or :. Without it we only propagate one problem from
> > plpgsql to others languages.
> >
> Please explain.
>
> Perhaps I am wrong, but plpgsql handles arsgument names before it
> passes the query to be executed. Please see:
>
> plpgsql/pl_comp.c/do_compile(...)/line: 393
>
> Regards,
> Gevik.
>

it's one from mystic bugs:

create table t(a integer, b integer);
insert into t values(10,20);

create function foo(a integer)
returns integer
as $$
  select a from t
where a <> b and a = 10;
$$ languge sql;

select foo(20);
output? expected 10, but you will get NULL!

Regards
Pavel Stehule

so some prefixes can help

create function foo(a integer)
returns integer
as $$
  select a from t
where :a <> b and a = 10;
$$ languge sql;

Oracle use symbol ':'

I don't know what others databases has.

Regards
Pavel Stehule

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [PATCHES] V0.1 patch for TODO Item: SQL-language reference parameters by name.

2007-11-02 Thread Tom Lane
"Gevik Babakhani" <[EMAIL PROTECTED]> writes:
>> what about name's collision? Maybe is better use some prefix, 
>> like $ or :. Without it we only propagate one problem from 
>> plpgsql to others languages.

> Please explain.
> Perhaps I am wrong, but plpgsql handles arsgument names before it
> passes the query to be executed.

Which is actually the Wrong Thing to do: really the parameters should be
seen as being in a name scope that's outside that of the query (and thus
ambiguous names should be resolved first as column names of the query).
The proposed patch does this in the right order and so I think that
Pavel's concern is without foundation.

One point here is that it would be good to be able to qualify the
argument names with the function name, for example

create function myfunc(x int) ...
select ... from t where t.x = myfunc.x

If t has a column named x then this will be the only way that the
function parameter x can be referenced within that query.  We are
partway to that point with plpgsql but haven't bitten the bullet
of changing the lookup order.

Note that this consideration is another reason for having a callback
function that's responsible for trying to resolve unresolved names.
I certainly wouldn't like to have a notion of "function name" wired
into the parser API, and if we did do that it still wouldn't be
sufficient for plpgsql which can have multiple block-label namespaces
accessible at once.

regards, tom lane

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [PATCHES] V0.1 patch for TODO Item: SQL-language reference parameters by name.

2007-11-02 Thread Tom Lane
"Gevik Babakhani" <[EMAIL PROTECTED]> writes:
> I am sending this patch to check if I am on the right track.
> So please take a look at this if possible.

You seem not to have understood my recommendation to use a callback
function.  This patch might work nicely for SQL functions but there
will be no good way to use it for plpgsql, or probably any other
PL function language.  If we're going to change the parser API
then I'd like to have a more general solution.

regards, tom lane

---(end of broadcast)---
TIP 5: don't forget to increase your free space map settings


Re: [PATCHES] V0.1 patch for TODO Item: SQL-language reference parameters by name.

2007-11-02 Thread Gevik Babakhani
 
Hi,
 
> what about name's collision? Maybe is better use some prefix, 
> like $ or :. Without it we only propagate one problem from 
> plpgsql to others languages.
> 
Please explain.

Perhaps I am wrong, but plpgsql handles arsgument names before it
passes the query to be executed. Please see:

plpgsql/pl_comp.c/do_compile(...)/line: 393

Regards,
Gevik.



---(end of broadcast)---
TIP 3: Have you checked our extensive FAQ?

   http://www.postgresql.org/docs/faq


Re: [PATCHES] V0.1 patch for TODO Item: SQL-language reference parameters by name.

2007-11-02 Thread Gevik Babakhani
Noted. Thank you.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Andrew Dunstan
Sent: Friday, November 02, 2007 4:19 PM
To: Gevik Babakhani
Cc: pgsql-patches@postgresql.org
Subject: Re: [PATCHES] V0.1 patch for TODO Item: SQL-language reference
parameters by name.



Gevik Babakhani wrote:
>
> Hello all,
>
>  
>
> Hereby an alpha version regarding the:
>
> TODO Item: SQL-language reference parameters by name.
>
>  
>
> I am sending this patch to check if I am on the right track.
>
> So please take a look at this if possible.
>

Step 1: don't use c++ style comments like this:

+   //TODO: Check here

C89 is basically our standard. gcc -std=c89 will check that it complies.

cheers

andrew


---(end of broadcast)---
TIP 6: explain analyze is your friend


---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [PATCHES] V0.1 patch for TODO Item: SQL-language reference parameters by name.

2007-11-02 Thread Pavel Stehule
> Hello all,
>
>
>
> Hereby an alpha version regarding the:
>
> TODO Item: SQL-language reference parameters by name.
>
>

what about name's collision? Maybe is better use some prefix, like $
or :. Without it we only propagate one problem from plpgsql to others
languages.

It can be more wide used:
* named params in prepared statements
* named params in SPI
* ..

Regards
Pavel Stehule

---(end of broadcast)---
TIP 1: if posting/reading through Usenet, please send an appropriate
   subscribe-nomail command to [EMAIL PROTECTED] so that your
   message can get through to the mailing list cleanly


Re: [PATCHES] V0.1 patch for TODO Item: SQL-language reference parameters by name.

2007-11-02 Thread Andrew Dunstan



Gevik Babakhani wrote:


Hello all,

 


Hereby an alpha version regarding the:

TODO Item: SQL-language reference parameters by name.

 


I am sending this patch to check if I am on the right track.

So please take a look at this if possible.



Step 1: don't use c++ style comments like this:

+   //TODO: Check here

C89 is basically our standard. gcc -std=c89 will check that it complies.

cheers

andrew


---(end of broadcast)---
TIP 6: explain analyze is your friend