Re: Calling PL functions with named parameters

From: Robert Treat <xzilla(at)users(dot)sourceforge(dot)net>
To: "Jim C(dot) Nasby" <decibel(at)decibel(dot)org>
Cc: David Fetter <david(at)fetter(dot)org>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Calling PL functions with named parameters
Date: 2004-08-14 01:18:10
Message-ID: 200408132118.10517.xzilla@users.sourceforge.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Would it be any better to allow

SELECT blah(1,DEFAULT);

?

Robert Treat

On Friday 13 August 2004 18:49, Jim C. Nasby wrote:
> I would personally find this useful, but I would suggest using Oracle's
> syntax of SELECT func(a=>2, b=>'b', ...);
>
> Having said that, having the concept of DEFAULT for parameters wolud be
> even more useful, ie:
>
> CREATE FUNCTION blah (
> a int
> , b int DEFAULT 0
> );
>
> SELECT blah(1,0);
> and
> SELECT blah(1);
> would do the same thing. (Yes, I know there's a work-around, but it's a
> bit of a pain if you've got 10 parameters that could be omitted).
>
> On Fri, Aug 13, 2004 at 02:41:48PM -0700, David Fetter wrote:
> > Kind people,
> >
> > I've brought this up before, and with Dennis Bjőrklund's help, would
> > like to bring it up again. Here's the idea:
> >
> > I'd like to be able to create functions with named parameters that
> > could be called with the names in any order. For example,
> >
> > CREATE OR REPLACE FUNCTION foo_func(name TEXT, val INTEGER) AS ...
> >
> > SELECT foo_func(val AS 23, name AS 'Name goes here');
> >
> > and have it Do The Right Thing.
> >
> > Dennis has pointed out that mixing the call-with-named-parameter
> > interface with call-by-order-of-parameters one would cause confusion,
> > and I think it would be OK to disallow this type mixing, so
> >
> > SELECT foo_func(name AS 'yet another name', 35);
> >
> > would be disallowed.
> >
> > A calling convention that names parameters makes it a lot easier to
> > track just exactly what parameter is set to which value, and lets
> > people not have to memorize what order those named parameters appear
> > in. On a related note, it would also be nice to have default
> > parameters and some way to say to use them.
> >
> > Well, that's my thoughts so far. What are yours?
> >
> > Cheers,
> > D
> > --
> > David Fetter david(at)fetter(dot)org http://fetter.org/
> > phone: +1 510 893 6100 mobile: +1 415 235 3778
> >
> > Remember to vote!
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 8: explain analyze is your friend

--
Robert Treat
Build A Better Lamp :: Linux Apache {middleware} PostgreSQL

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2004-08-14 01:30:47 Re: [PERFORM] Reiser4
Previous Message Robert Treat 2004-08-14 01:13:52 Re: Development Schedule Page