Thread: function parameters
Is it possible for funtions to have named parameters rather than just positional parameters? -JimC -- James Cloos <cloos@jhcloos.com> OpenPGP: 0xED7DAEA6
> Is it possible for funtions to have named parameters rather than just > positional parameters? I am not sure that every procedural language is the same, but with plpgsql: www.postgresql.org/docs/8.1/interactive/plpgsql-declarations.html#PLPGSQL-DECLARATION-ALIASES is seems that you can. Regards, Richard Broersma Jr.
>>>>> "RB" == Richard Broersma <rabroersma@yahoo.com> writes: JC> Is it possible for funtions to have named parameters rather than JC> just positional parameters? RB> I am not sure that every procedural language is the same, but with plpgsql: RB> www.postgresql.org/docs/8.1/interactive/plpgsql-declarations.html#PLPGSQL-DECLARATION-ALIASES RB> is seems that you can. Thanks for that. I was hoping for something more akin to what perl offers (passing a hash rather than an array). After reading that bit of the docs, I suppose I could have the array take a pair of arrays, one with the names and one with the values. But it seems more likely I'll end up moving that logic out of the sql and into the code generating and submitting the sql. That code is expected to be the only code doing INSERTs, so it should still be sufficiently robust for this project. The reply and this reply have helped me get a better handle on what I want, need and how to do it. -JimC -- James Cloos <cloos@jhcloos.com> OpenPGP: 0xED7DAEA6
>>>>> "Richard" == Richard Broersma <rabroersma@yahoo.com> writes: >> Is it possible for funtions to have named parameters rather than just >> positional parameters? Richard> I am not sure that every procedural language is the same, but with plpgsql: Richard> www.postgresql.org/docs/8.1/interactive/plpgsql-declarations.html#PLPGSQL-DECLARATION-ALIASES I meant to reply again to this. I wound up with a staging table with a before trigger which calls the function. So, instead of "SELECT foobar()" I "INSERT INTO staging". The columns of staging are what the arguments to foobar() would have been, and foobar gets the data from OLD (or $_TD->{new} in plperl¹). Thanks again. The hint led me to the fountain. -JimC ¹ cf my post in docs about $_TD->{old} -- James Cloos <cloos@jhcloos.com> OpenPGP: 0xED7DAEA6