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

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Jim Nasby <jim(at)nasby(dot)net>, Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: WIP: Allow SQL-language functions to reference parameters by parameter name
Date: 2011-04-18 12:33:06
Message-ID: BANLkTin4RK+eL3bV8wBsUj3O=VOY2hB=0Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Apr 14, 2011 at 10:56 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> 2011/4/15 Jim Nasby <jim(at)nasby(dot)net>:
>> On Apr 14, 2011, at 4:20 PM, Kevin Grittner wrote:
>>> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>>> Robert Haas <robertmhaas(at)gmail(dot)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
>>>> parameter names to be checked only after query names is probably
>>>> the best answer.
>>>
>>> +1
>>>
>>> That seems the most useful and least surprising approach to me.
>>
>> As part of this, can we also allow specifying an alias for the function name? That would make it far less onerous to disambiguate parameters. Unfortunately we obviously couldn't use AS as the keyword for this alias; maybe we could use ALIAS instead? IE:
>>
>> CREATE FUNCTION function_with_really_really_descriptive_name (
>>  some_parameter int
>> ) RETURNS int LANGUAGE SQL ALIAS fwrrdn AS $$
>>        SELECT fwrrdn.some_parameter
>> $$;
>> --
>
> I see this can be problem for other languages - mainly for PLpgSQL.
> There should be aliases supported too. And this small feature can be
> terible when somebody will try to port your code to other platforms.
> Personally I am thinking, so it isn't necessary
>
> -1

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 even better, in my view, is having a short alias that is
defined by default, but all previous proposals in this vein have been
shot down by Tom and Andrew. As a practical matter, though, I think
what Jim is talking about speaks to a real need - people want to make
SQL function names long and descriptive, but they do NOT want to spell
out that long function name 16 times inside the function body.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Leonardo Francalanci 2011-04-18 12:36:13 Re: switch UNLOGGED to LOGGED
Previous Message Andrew Dunstan 2011-04-18 12:29:22 Re: Formatting Curmudgeons WAS: MMAP Buffers