Re: [HACKERS] named parameters in SQL functions

2009-11-16 Thread Peter Eisentraut
On sön, 2009-11-15 at 12:37 -0500, Andrew Dunstan wrote: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name. Essentially, ISTM, we

[HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Dunstan
At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name. Essentially, ISTM, we could use some special marker such as @ (c.f. SQL Server)

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Chernow
Andrew Dunstan wrote: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name. Essentially, ISTM, we could use some special marker such

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Pavel Stehule
2009/11/15 Andrew Dunstan and...@dunslane.net: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name. Essentially, ISTM, we could use

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Pavel Stehule
2009/11/15 Andrew Chernow a...@esilo.com: Andrew Dunstan wrote: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name. Essentially,

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Robert Haas
On Sun, Nov 15, 2009 at 12:37 PM, Andrew Dunstan and...@dunslane.net wrote: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name.

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Greg Stark
On Sun, Nov 15, 2009 at 5:49 PM, Andrew Chernow a...@esilo.com wrote: Andrew Dunstan wrote: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread David E. Wheeler
On Nov 15, 2009, at 10:19 AM, Greg Stark wrote: I like the special marker idea. A '$' would be nice because its already in use for similar purposes, but I think that would lead to ambiguity with dollar quoting. I think that would be a big break with everything else and very non-sql-ish.

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Pavel Stehule
2009/11/15 David E. Wheeler da...@kineticode.com: On Nov 15, 2009, at 10:19 AM, Greg Stark wrote: I like the special marker idea.  A '$' would be nice because its already in use for similar purposes, but I think that would lead to ambiguity with dollar quoting. I think that would be a big

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Greg Stark
On Sun, Nov 15, 2009 at 6:42 PM, Pavel Stehule pavel.steh...@gmail.com wrote: Personally, I like $var, but @var would be okay, and @@var is acceptable. But I'm JAPH, so my biases should be obvious. @var or @@var should be a break for people from MySQL. @var are r/w in MySQL and @@var are

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Greg Stark
On Sun, Nov 15, 2009 at 6:26 PM, David E. Wheeler da...@kineticode.com wrote: Personally, I like $var, but @var would be okay, and @@var is acceptable. But I'm JAPH, so my biases should be obvious. I'm japh too -- but that doesn't mean grabbing one little aesthetic from Perl without copying

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Brendan Jurd
2009/11/16 Andrew Dunstan and...@dunslane.net: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name. Essentially, ISTM, we could use

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Pavel Stehule
2009/11/15 Greg Stark gsst...@mit.edu: On Sun, Nov 15, 2009 at 6:42 PM, Pavel Stehule pavel.steh...@gmail.com wrote: Personally, I like $var, but @var would be okay, and @@var is acceptable. But I'm JAPH, so my biases should be obvious. @var or @@var should be a break for people from

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread David E. Wheeler
On Nov 15, 2009, at 10:54 AM, Greg Stark wrote: I'm japh too -- but that doesn't mean grabbing one little aesthetic from Perl without copying the whole concept behind it makes any sense. Perl sigils are an important part of the language and are a basic part of the syntax. They aren't just a

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Chernow
I like the special marker idea. A '$' would be nice because its already in use for similar purposes, but I think that would lead to ambiguity with dollar quoting. no, it should be safe (if you don't use for dollar quoting some like $variablename$) Actually, I was thinking of something

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Pavel Stehule
2009/11/15 Andrew Chernow a...@esilo.com: I like the special marker idea.  A '$' would be nice because its already in use for similar purposes, but I think that would lead to ambiguity with dollar quoting. no, it should be safe (if you don't use for dollar quoting some like $variablename$)

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Greg Stark
On Sun, Nov 15, 2009 at 6:26 PM, David E. Wheeler da...@kineticode.com wrote: Moreover you would still have conflicts possible because sql can quote identifiers so people can have columns named $foo. You would have a weird syntactic detail where $foo would mean something different than $foo

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread David E. Wheeler
On Nov 15, 2009, at 11:21 AM, Greg Stark wrote: No, that's not the same. The point is that $ is a perfectly valid SQL identifier character and $foo is a perfectly valid identifier. You can always quote any identifier (yes, after case smashing) so you would expect if $foo is a valid

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Greg Stark
On Sun, Nov 15, 2009 at 7:25 PM, David E. Wheeler da...@kineticode.com wrote: On Nov 15, 2009, at 11:21 AM, Greg Stark wrote: $foo should be killed off as a valid identifier, IMNSHO. But failing that, some other sigil would be most welcome. I don't think SQL is the height of language design

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Dunstan
David E. Wheeler wrote: $foo should be killed off as a valid identifier, IMNSHO. It's only legal when quoted. Unquoted indetifiers can't begin with $. see scan.l: ident_start [A-Za-z\200-\377_] ident_cont [A-Za-z\200-\377_0-9\$] identifier

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Chernow
The point is that $ is a perfectly valid SQL identifier character and $foo is a perfectly valid identifier. You can always quote any identifier (yes, after case smashing) so you would expect if $foo is a valid identifier then $foo would refer to the same identifier. This case already exists

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Greg Stark
On Sun, Nov 15, 2009 at 7:56 PM, Andrew Chernow a...@esilo.com wrote: The point is that $ is a perfectly valid SQL identifier character and $foo is a perfectly valid identifier. You can always quote any identifier (yes, after case smashing) so you would expect if $foo is a valid identifier

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread David E. Wheeler
On Nov 15, 2009, at 12:09 PM, Greg Stark wrote: 1) Error messages which mention column names are supposed to quote the column name to set it apart from the error string. This also guarantees that weird column names are referenced correctly as foo bar or $foo so the reference in the error

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread David E. Wheeler
On Nov 15, 2009, at 11:35 AM, Greg Stark wrote: I don't think SQL is the height of language design either. But trying to turn it into another language piece by piece is not gong to make it any nicer. I don't know of anyone suggesting such a thing. A sigil here doesn't accomplish anything.

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Tom Lane
Andrew Dunstan and...@dunslane.net writes: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name. Throw error if ambiguous. We

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Dunstan
Tom Lane wrote: Andrew Dunstan and...@dunslane.net writes: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we would disambiguate a parameter name from a column name. Throw

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Robert Haas
On Sun, Nov 15, 2009 at 8:22 PM, Andrew Dunstan and...@dunslane.net wrote: Tom Lane wrote: Andrew Dunstan and...@dunslane.net writes: At Tom's suggestion I am looking at allowing use of parameter names in SQL functions instead of requiring use of $1 etc. That raises the question of how we

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Sun, Nov 15, 2009 at 8:22 PM, Andrew Dunstan and...@dunslane.net wrote: Well, if the funcname.varname gadget will work, as you suggest elsewhere it could, I think that would suffice. I had assumed that was just something in the plpgsql engine.

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Chernow
Tom Lane wrote: Robert Haas robertmh...@gmail.com writes: On Sun, Nov 15, 2009 at 8:22 PM, Andrew Dunstan and...@dunslane.net wrote: Well, if the funcname.varname gadget will work, as you suggest elsewhere it could, I think that would suffice. I had assumed that was just something in the

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Tom Lane
Andrew Chernow a...@esilo.com writes: Tom Lane wrote: (But having said that, an alternate qualification name is something that could be implemented if there were any agreement on what to use.) Would something like ARG.name be acceptable? It all depends on how likely you think it is that the

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Chernow
Tom Lane wrote: Andrew Chernow a...@esilo.com writes: Tom Lane wrote: (But having said that, an alternate qualification name is something that could be implemented if there were any agreement on what to use.) Would something like ARG.name be acceptable? It all depends on how likely you

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Tom Lane
Andrew Chernow a...@esilo.com writes: Tom Lane wrote: It's certainly true that the function name itself is not immune from conflicts of that sort ... in fact I think we saw a bug report recently from someone who had intentionally chosen a plpgsql function name equal to a table name used in

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Robert Haas
On Sun, Nov 15, 2009 at 8:40 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Sun, Nov 15, 2009 at 8:22 PM, Andrew Dunstan and...@dunslane.net wrote: Well, if the funcname.varname gadget will work, as you suggest elsewhere it could, I think that would

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Dunstan
Robert Haas wrote: (But having said that, an alternate qualification name is something that could be implemented if there were any agreement on what to use.) Well that is the tricky part, for sure. I would personally prefer something like ${name} rather than a prefix, but I think

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Robert Haas
On Sun, Nov 15, 2009 at 9:52 PM, Andrew Dunstan and...@dunslane.net wrote: Robert Haas wrote: (But having said that, an alternate qualification name is something that could be implemented if there were any agreement on what to use.) Well that is the tricky part, for sure.  I would

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Tom Lane
Andrew Dunstan and...@dunslane.net writes: Robert Haas wrote: Well that is the tricky part, for sure. I would personally prefer something like ${name} rather than a prefix, but I think you're likely to veto that outright. So, anything reasonably short would be an improvement over the status

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: I don't see why it would need to be a reserved word. We're not changing how it gets parsed, just what it means. At any rate FUNCTION. is a 9-character prefix, which is rather longer than I would prefer. This from the guy who likes 40-character

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Andrew Dunstan
Robert Haas wrote: On Sun, Nov 15, 2009 at 9:52 PM, Andrew Dunstan and...@dunslane.net wrote: Robert Haas wrote: (But having said that, an alternate qualification name is something that could be implemented if there were any agreement on what to use.) Well that is the

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Robert Haas
On Sun, Nov 15, 2009 at 10:05 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: I don't see why it would need to be a reserved word.  We're not changing how it gets parsed, just what it means.  At any rate FUNCTION. is a 9-character prefix, which is rather longer

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Robert Haas
On Sun, Nov 15, 2009 at 10:14 PM, Andrew Dunstan and...@dunslane.net wrote: Robert Haas wrote: On Sun, Nov 15, 2009 at 9:52 PM, Andrew Dunstan and...@dunslane.net wrote: Robert Haas wrote: (But having said that, an alternate qualification name is something that could be implemented if there

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Pavel Stehule
2009/11/16 Andrew Dunstan and...@dunslane.net: Robert Haas wrote: On Sun, Nov 15, 2009 at 9:52 PM, Andrew Dunstan and...@dunslane.net wrote: Robert Haas wrote: (But having said that, an alternate qualification name is something that could be implemented if there were any agreement on

Re: [HACKERS] named parameters in SQL functions

2009-11-15 Thread Pavel Stehule
2009/11/16 Robert Haas robertmh...@gmail.com: On Sun, Nov 15, 2009 at 10:14 PM, Andrew Dunstan and...@dunslane.net wrote: Robert Haas wrote: On Sun, Nov 15, 2009 at 9:52 PM, Andrew Dunstan and...@dunslane.net wrote: Robert Haas wrote: (But having said that, an alternate qualification name is