Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-26 Thread Dimitri Fontaine
(oops this mail never reached out, it seems, resending) Kevin Grittner kevin.gritt...@wicourts.gov writes: Tom Lane t...@sss.pgh.pa.us wrote: Yeah, I've come round to that position too. I think allowing parameter names to be checked only after query names is probably the best answer.

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-18 Thread Robert Haas
On Thu, Apr 14, 2011 at 10:56 PM, Pavel Stehule pavel.steh...@gmail.com wrote: 2011/4/15 Jim Nasby j...@nasby.net: On Apr 14, 2011, at 4:20 PM, Kevin Grittner wrote: Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: So far the most promising proposal I've seen

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-18 Thread Alvaro Herrera
Excerpts from Robert Haas's message of lun abr 18 09:33:06 -0300 2011: I don't much like Jim's syntax suggestion (the alias really ought to be declared within the function body, I think, not added to the CREATE FUNCTION statement) but I don't necessarily think it's a bad idea. What would be

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-18 Thread Merlin Moncure
On Mon, Apr 18, 2011 at 11:33 AM, Alvaro Herrera alvhe...@commandprompt.com wrote: Excerpts from Robert Haas's message of lun abr 18 09:33:06 -0300 2011: I don't much like Jim's syntax suggestion (the alias really ought to be declared within the function body, I think, not added to the CREATE

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-14 Thread Dimitri Fontaine
Robert Haas robertmh...@gmail.com writes: rhaas=# CREATE OR REPLACE FUNCTION developer_lookup(id integer) RETURNS text AS $$SELECT name FROM developer WHERE id = $1$$ LANGUAGE sql STABLE; Now, when this person attempts to recreate this function on a hypothetical version of PostgreSQL that

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-14 Thread Robert Haas
On Thu, Apr 14, 2011 at 11:37 AM, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Robert Haas robertmh...@gmail.com writes: rhaas=# CREATE OR REPLACE FUNCTION developer_lookup(id integer) RETURNS text AS $$SELECT name FROM developer WHERE id = $1$$ LANGUAGE sql STABLE; Now, when this person

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-14 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Thu, Apr 14, 2011 at 11:37 AM, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Unless we make it so that no such version ever exists.  Meaning that the code works fine as is or using WHERE id = developer_lookup.id.  AS id can't ever be the parameter

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-14 Thread Robert Haas
On Thu, Apr 14, 2011 at 1:55 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Thu, Apr 14, 2011 at 11:37 AM, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Unless we make it so that no such version ever exists.  Meaning that the code works fine as is or

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-14 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Thu, Apr 14, 2011 at 1:55 PM, Tom Lane t...@sss.pgh.pa.us wrote: Hmm, what I read Dimitri to be proposing is that we *require* parameter names to be qualified with the function name.  I don't recall hearing that before.  It would solve the problem

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-14 Thread Kevin Grittner
Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: So far the most promising proposal I've seen seems to be to let id mean the parameter called id only when it can't refer to anything in the query. Yeah, I've come round to that position too. I think allowing

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-14 Thread Jim Nasby
On Apr 14, 2011, at 4:20 PM, Kevin Grittner wrote: Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: So far the most promising proposal I've seen seems to be to let id mean the parameter called id only when it can't refer to anything in the query. Yeah, I've

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-14 Thread Pavel Stehule
2011/4/15 Jim Nasby j...@nasby.net: On Apr 14, 2011, at 4:20 PM, Kevin Grittner wrote: Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: So far the most promising proposal I've seen seems to be to let id mean the parameter called id only when it can't refer to

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Andrew Dunstan
On 04/07/2011 09:58 PM, Tom Lane wrote: Robert Haasrobertmh...@gmail.com writes: On Tue, Apr 5, 2011 at 5:52 PM, Andrew Dunstanand...@dunslane.net wrote: That doesn't mean we should arbitrarily break compatibility with pl/sql, nor that we should feel free to add on warts such as $varname

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Pavel Stehule
Hello Well, if we're going to consider 100% backwards compatibility a must, then we should just stick with what the submitted patch does, ie, unqualified names are matched first to query columns, and to parameters only if there's no column match.  This is also per spec if I interpreted

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Andrew Dunstan
On 04/08/2011 10:53 AM, Pavel Stehule wrote: For SQL language functions, I think you're right. The only caveat I have is that if your function name is very long, having to use it as a disambiguating qualifier can be a bit ugly. same mechanism works well in plpgsql and nobody requested a some

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Robert Haas
On Fri, Apr 8, 2011 at 10:53 AM, Pavel Stehule pavel.steh...@gmail.com wrote: same mechanism works well in plpgsql and nobody requested a some special shortcut. I did. That mechanism sucks. But I think we're committed to doing what the standard and/or Oracle do, so oh well. -- Robert Haas

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Andres Freund
On Friday, April 08, 2011 04:53:27 PM Pavel Stehule wrote: same mechanism works well in plpgsql and nobody requested a some special shortcut. Well, for one it sucks there as well. For another it has been introduced for quite some time and most people have introduced naming like p_param or

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread David E. Wheeler
On Apr 8, 2011, at 8:05 AM, Robert Haas wrote: same mechanism works well in plpgsql and nobody requested a some special shortcut. I did. That mechanism sucks. But I think we're committed to doing what the standard and/or Oracle do, so oh well. I think I've worked around that in PL/pgSQL

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Robert Haas
On Fri, Apr 8, 2011 at 11:51 AM, David E. Wheeler da...@kineticode.com wrote: On Apr 8, 2011, at 8:05 AM, Robert Haas wrote: same mechanism works well in plpgsql and nobody requested a some special shortcut. I did.  That mechanism sucks.  But I think we're committed to doing what the

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Merlin Moncure
On Thu, Apr 7, 2011 at 8:58 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Tue, Apr 5, 2011 at 5:52 PM, Andrew Dunstan and...@dunslane.net wrote: That doesn't mean we should arbitrarily break compatibility with pl/sql, nor that we should feel free to add on

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Tom Lane
Merlin Moncure mmonc...@gmail.com writes: On Thu, Apr 7, 2011 at 8:58 PM, Tom Lane t...@sss.pgh.pa.us wrote: Well, if we're going to consider 100% backwards compatibility a must, then we should just stick with what the submitted patch does, ie, unqualified names are matched first to query

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Josh Berkus
But breaking people's code is not a better answer. We still have people on 8.2 because the pain of upgrading to 8.3 is more than they can bear, and how many releases have we spent trying to get standard_conforming_strings worked out? I admit this probably wouldn't be as bad, but we've

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Robert Haas
On Fri, Apr 8, 2011 at 3:56 PM, Josh Berkus j...@agliodbs.com wrote: But breaking people's code is not a better answer.  We still have people on 8.2 because the pain of upgrading to 8.3 is more than they can bear, and how many releases have we spent trying to get standard_conforming_strings

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Josh Berkus
Now, when this person attempts to recreate this function on a hypothetical version of PostgreSQL that thinks id is ambiguous, it doesn't work. Hence the GUC. Where's the issue? -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via pgsql-hackers mailing list

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Robert Haas
On Fri, Apr 8, 2011 at 4:32 PM, Josh Berkus j...@agliodbs.com wrote: Now, when this person attempts to recreate this function on a hypothetical version of PostgreSQL that thinks id is ambiguous, it doesn't work. Hence the GUC.   Where's the issue? Behavior-changing GUCs for this kind of

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Fri, Apr 8, 2011 at 4:32 PM, Josh Berkus j...@agliodbs.com wrote: Hence the GUC.   Where's the issue? Behavior-changing GUCs for this kind of thing cause a lot of problems. If you need one GUC setting for your application to work, and the

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-08 Thread Pavel Stehule
2011/4/9 Tom Lane t...@sss.pgh.pa.us: Robert Haas robertmh...@gmail.com writes: On Fri, Apr 8, 2011 at 4:32 PM, Josh Berkus j...@agliodbs.com wrote: Hence the GUC.   Where's the issue? Behavior-changing GUCs for this kind of thing cause a lot of problems.  If you need one GUC setting for

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-07 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Tue, Apr 5, 2011 at 5:52 PM, Andrew Dunstan and...@dunslane.net wrote: That doesn't mean we should arbitrarily break compatibility with pl/sql, nor that we should feel free to add on warts such as $varname that are completely at odds with the style

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-07 Thread David E. Wheeler
On Apr 7, 2011, at 6:58 PM, Tom Lane wrote: Well, if we're going to consider 100% backwards compatibility a must, then we should just stick with what the submitted patch does, ie, unqualified names are matched first to query columns, and to parameters only if there's no column match. This is

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-07 Thread Robert Haas
On Thu, Apr 7, 2011 at 9:58 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Tue, Apr 5, 2011 at 5:52 PM, Andrew Dunstan and...@dunslane.net wrote: That doesn't mean we should arbitrarily break compatibility with pl/sql, nor that we should feel free to add on

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-07 Thread Darren Duncan
Robert Haas wrote: I am halfway tempted to say that we need to invent our own procedural language that is designed not for compatibility with the SQL standard or Oracle, but for non-crappiness. I'm way ahead of you on that one. -- Darren Duncan -- Sent via pgsql-hackers mailing list

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Jim Nasby
On Mar 28, 2011, at 3:18 PM, Peter Eisentraut wrote: On lör, 2011-03-26 at 09:41 -0400, Robert Haas wrote: You can't be guaranteed that they won't standardize something incompatible no matter what we do. We could choose to do it as you've proposed and they could then standardize some weird

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Merlin Moncure
On Fri, Mar 25, 2011 at 10:05 PM, David E. Wheeler da...@kineticode.com wrote: On Mar 25, 2011, at 9:12 PM, Robert Haas wrote: As I've said before, I believe that the root cause of this problem is that using the same syntax for variables and column names is a bad idea in the first place.  If

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Peter Eisentraut
On tis, 2011-04-05 at 11:21 -0500, Merlin Moncure wrote: +1 on using $foo. Even with the standardization risk I think it's the best choice. Prefer $foo to ${foo} though. What standardization risk? The standard has already existed for 10 years and is widely implemented. -- Sent via

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Robert Haas
On Tue, Apr 5, 2011 at 1:45 PM, Peter Eisentraut pete...@gmx.net wrote: On tis, 2011-04-05 at 11:21 -0500, Merlin Moncure wrote: +1 on using $foo.  Even with the standardization risk I think it's the best choice. Prefer $foo to ${foo} though. What standardization risk?  The standard has

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Darren Duncan
Merlin Moncure wrote: On Fri, Mar 25, 2011 at 10:05 PM, David E. Wheeler da...@kineticode.com wrote: On Mar 25, 2011, at 9:12 PM, Robert Haas wrote: As I've said before, I believe that the root cause of this problem is that using the same syntax for variables and column names is a bad idea in

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Peter Eisentraut
On tis, 2011-04-05 at 15:05 -0400, Robert Haas wrote: On Tue, Apr 5, 2011 at 1:45 PM, Peter Eisentraut pete...@gmx.net wrote: On tis, 2011-04-05 at 11:21 -0500, Merlin Moncure wrote: +1 on using $foo. Even with the standardization risk I think it's the best choice. Prefer $foo to ${foo}

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Merlin Moncure
On Tue, Apr 5, 2011 at 2:33 PM, Peter Eisentraut pete...@gmx.net wrote: On tis, 2011-04-05 at 15:05 -0400, Robert Haas wrote: On Tue, Apr 5, 2011 at 1:45 PM, Peter Eisentraut pete...@gmx.net wrote: On tis, 2011-04-05 at 11:21 -0500, Merlin Moncure wrote: +1 on using $foo.  Even with the

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Pavel Stehule
2011/4/5 Peter Eisentraut pete...@gmx.net: On tis, 2011-04-05 at 15:05 -0400, Robert Haas wrote: On Tue, Apr 5, 2011 at 1:45 PM, Peter Eisentraut pete...@gmx.net wrote: On tis, 2011-04-05 at 11:21 -0500, Merlin Moncure wrote: +1 on using $foo.  Even with the standardization risk I think it's

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Pavel Stehule
2011/4/5 Merlin Moncure mmonc...@gmail.com: On Tue, Apr 5, 2011 at 2:33 PM, Peter Eisentraut pete...@gmx.net wrote: On tis, 2011-04-05 at 15:05 -0400, Robert Haas wrote: On Tue, Apr 5, 2011 at 1:45 PM, Peter Eisentraut pete...@gmx.net wrote: On tis, 2011-04-05 at 11:21 -0500, Merlin Moncure

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Peter Eisentraut
On tis, 2011-04-05 at 14:45 -0500, Merlin Moncure wrote: Talking about the standards compliance of functions is a bit silly: our implementation of functions isn't even close to approximating what looks to be the standard That doesn't mean it couldn't be better in the future. We shouldn't take

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Merlin Moncure
On Tue, Apr 5, 2011 at 3:47 PM, Peter Eisentraut pete...@gmx.net wrote: On tis, 2011-04-05 at 14:45 -0500, Merlin Moncure wrote: Talking about the standards compliance of functions is a bit silly: our implementation of functions isn't even close to approximating what looks to be the standard

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Andrew Dunstan
On 04/05/2011 03:45 PM, Merlin Moncure wrote: Talking about the standards compliance of functions is a bit silly: our implementation of functions isn't even close to approximating what looks to be the standard (according to this at least:

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-04-05 Thread Robert Haas
On Tue, Apr 5, 2011 at 5:52 PM, Andrew Dunstan and...@dunslane.net wrote: That doesn't mean we should arbitrarily break compatibility with pl/sql, nor that we should feel free to add on warts such as $varname that are completely at odds with the style of the rest of the language. That doesn't

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-28 Thread Peter Eisentraut
On lör, 2011-03-26 at 09:41 -0400, Robert Haas wrote: You can't be guaranteed that they won't standardize something incompatible no matter what we do. We could choose to do it as you've proposed and they could then standardize some weird syntax - the = is a fairly relevant example of exactly

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-27 Thread Dimitri Fontaine
Robert Haas robertmh...@gmail.com writes: On Sat, Mar 26, 2011 at 5:19 PM, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: I think the best choice is to only accept qualified parameter names in SQL functions (function_name.parameter_name).  If a referenced table share the function's name,

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-27 Thread Robert Haas
On Mar 27, 2011, at 6:11 AM, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: Robert Haas robertmh...@gmail.com writes: That syntax is sufficiently unwieldly that few people will want to use it in real life, but certainly the backward compatibility problem is much less than with what Tom

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-27 Thread David Fetter
On Fri, Mar 25, 2011 at 09:12:33PM -0400, Robert Haas wrote: On Fri, Mar 25, 2011 at 8:58 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Mar 25, 2011, at 7:45 PM, Tom Lane t...@sss.pgh.pa.us wrote: Well, maybe, but it's not like it's subtle or hard to

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-27 Thread Andrew Dunstan
On 03/27/2011 09:42 AM, David Fetter wrote: On Fri, Mar 25, 2011 at 09:12:33PM -0400, Robert Haas wrote: As I've said before, I believe that the root cause of this problem is that using the same syntax for variables and column names is a bad idea in the first place. If we used $foo or ?foo

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-27 Thread Pavel Stehule
2011/3/27 Andrew Dunstan and...@dunslane.net: On 03/27/2011 09:42 AM, David Fetter wrote: On Fri, Mar 25, 2011 at 09:12:33PM -0400, Robert Haas wrote: As I've said before, I believe that the root cause of this problem is that using the same syntax for variables and column names is a bad

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-27 Thread Martijn van Oosterhout
On Sun, Mar 27, 2011 at 06:52:03PM +0200, Pavel Stehule wrote: Syntax for named parameters should be consistent with prepared statement. Is there any comments in standard? Well, there's section 4.24 which says: In SQL-statements that are executed dynamically, the parameters are called dynamic

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-27 Thread Pavel Stehule
2011/3/27 Martijn van Oosterhout klep...@svana.org: On Sun, Mar 27, 2011 at 06:52:03PM +0200, Pavel Stehule wrote: Syntax for named parameters should be consistent with prepared statement. Is there any comments in standard? Well, there's section 4.24 which says: In SQL-statements that are

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-26 Thread David E. Wheeler
On Mar 25, 2011, at 11:23 PM, Tom Lane wrote: If this were PL/perl, or PL/almost-anything-except-SQL, I could get behind such a proposal. But it's not, it's SQL; and SQL doesn't do things that way. SQL's idea of disambiguation is qualified names. And even more to the point: to the extent

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-26 Thread Robert Haas
On Mar 25, 2011, at 11:23 PM, Tom Lane t...@sss.pgh.pa.us wrote: If this were PL/perl, or PL/almost-anything-except-SQL, I could get behind such a proposal. But it's not, it's SQL; and SQL doesn't do things that way. SQL's idea of disambiguation is qualified names. And even more to the

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-26 Thread Dimitri Fontaine
Joshua Berkus j...@agliodbs.com writes: Personally I'd vote for *not* having any such dangerous semantics as that. We should have learned better by now from plpgsql experience. I think the best idea is to throw error for ambiguous references, period. As a likely heavy user of this feature,

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-26 Thread Pavel Stehule
2011/3/26 Dimitri Fontaine dimi...@2ndquadrant.fr: Joshua Berkus j...@agliodbs.com writes: Personally I'd vote for *not* having any such dangerous semantics as that. We should have learned better by now from plpgsql experience. I think the best idea is to throw error for ambiguous references,

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-26 Thread Robert Haas
On Sat, Mar 26, 2011 at 5:19 PM, Dimitri Fontaine dimi...@2ndquadrant.fr wrote: I think the best choice is to only accept qualified parameter names in SQL functions (function_name.parameter_name).  If a referenced table share the function's name, ERROR out and HINT to alias the table name. If

[HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Matthew Draper
Attached is a WIP patch that allows SQL-language functions to reference their parameters by name. It uses p_post_columnref_hook, so potentially ambiguous references prefer the column... that seems to make the most sense, both because it avoids a backwards incompatibility, and it conforms with

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Tom Lane
Matthew Draper matt...@trebex.net writes: Attached is a WIP patch that allows SQL-language functions to reference their parameters by name. It uses p_post_columnref_hook, so potentially ambiguous references prefer the column... that seems to make the most sense, both because it avoids a

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Pavel Stehule
2011/3/25 Tom Lane t...@sss.pgh.pa.us: Matthew Draper matt...@trebex.net writes: Attached is a WIP patch that allows SQL-language functions to reference their parameters by name. It uses p_post_columnref_hook, so potentially ambiguous references prefer the column... that seems to make the

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Tom Lane
Pavel Stehule pavel.steh...@gmail.com writes: 2011/3/25 Tom Lane t...@sss.pgh.pa.us: I think the best idea is to throw error for ambiguous references, period. There can be GUC for controlling use or don't use a parameter names. I am for GUC, because there will be a bilion conflicts. But a

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Pavel Stehule
2011/3/25 Tom Lane t...@sss.pgh.pa.us: Pavel Stehule pavel.steh...@gmail.com writes: 2011/3/25 Tom Lane t...@sss.pgh.pa.us: I think the best idea is to throw error for ambiguous references, period. There can be GUC for controlling use or don't use a parameter names. I am for GUC, because

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Robert Haas
On Mar 25, 2011, at 4:20 PM, Tom Lane t...@sss.pgh.pa.us wrote: GUCs are not tremendously helpful for problems such as this. If we actually wanted to preserve full backwards compatibility, we'd need to think of a way to mark SQL functions per-function as to what to do. But I don't think

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Mar 25, 2011, at 4:20 PM, Tom Lane t...@sss.pgh.pa.us wrote: But I don't think that's necessary. Up to now there's been relatively little use for naming the parameters of SQL functions, so I think there will be few conflicts in the field if we just

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Robert Haas
On Mar 25, 2011, at 7:45 PM, Tom Lane t...@sss.pgh.pa.us wrote: Well, maybe, but it's not like it's subtle or hard to fix. Depends how much of it you have. I've become very skeptical of anything that breaks pg_dump-and-reload-ability. And doubly so now that such problems also mean breaking

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Mar 25, 2011, at 7:45 PM, Tom Lane t...@sss.pgh.pa.us wrote: Well, maybe, but it's not like it's subtle or hard to fix. Depends how much of it you have. I've become very skeptical of anything that breaks pg_dump-and-reload-ability. This wouldn't

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Robert Haas
On Fri, Mar 25, 2011 at 8:58 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: On Mar 25, 2011, at 7:45 PM, Tom Lane t...@sss.pgh.pa.us wrote: Well, maybe, but it's not like it's subtle or hard to fix. Depends how much of it you have. I've become very skeptical

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Joshua Berkus
Tom, Personally I'd vote for *not* having any such dangerous semantics as that. We should have learned better by now from plpgsql experience. I think the best idea is to throw error for ambiguous references, period. As a likely heavy user of this feature, I agree with Tom here. I really

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Robert Haas
On Mar 25, 2011, at 9:22 PM, Joshua Berkus j...@agliodbs.com wrote: Tom, Personally I'd vote for *not* having any such dangerous semantics as that. We should have learned better by now from plpgsql experience. I think the best idea is to throw error for ambiguous references, period. As

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: On Mar 25, 2011, at 9:22 PM, Joshua Berkus j...@agliodbs.com wrote: Also, I don't understand why this would be a dump/reload issue if $1 and $2 continue to work. Because an identifier that previously referred unambiguously to a column might now be

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread David E. Wheeler
On Mar 25, 2011, at 9:12 PM, Robert Haas wrote: As I've said before, I believe that the root cause of this problem is that using the same syntax for variables and column names is a bad idea in the first place. If we used $foo or ?foo or ${foo} or $.foo or foo!!$#? to mean the parameter

Re: [HACKERS] WIP: Allow SQL-language functions to reference parameters by parameter name

2011-03-25 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: As I've said before, I believe that the root cause of this problem is that using the same syntax for variables and column names is a bad idea in the first place. If we used $foo or ?foo or ${foo} or $.foo or foo!!$#? to mean the parameter called foo,