Unix Technical Forum

function parameters

This is a discussion on function parameters within the pgsql Novice forums, part of the PostgreSQL category; --> Is it possible for funtions to have named parameters rather than just positional parameters? -JimC -- James Cloos <cloos@jhcloos.com> ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:09 PM
James Cloos
 
Posts: n/a
Default function parameters

Is it possible for funtions to have named parameters rather than just
positional parameters?

-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 0xED7DAEA6

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:09 PM
Richard Broersma Jr
 
Posts: n/a
Default Re: function parameters

> 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:
http://www.postgresql.org/docs/8.1/i...RATION-ALIASES

is seems that you can.

Regards,

Richard Broersma Jr.

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 10:09 PM
James Cloos
 
Posts: n/a
Default Re: function parameters

>>>>> "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> http://www.postgresql.org/docs/8.1/i...RATION-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



---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 10:10 PM
James Cloos
 
Posts: n/a
Default Re: function parameters

>>>>> "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> http://www.postgresql.org/docs/8.1/i...RATION-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

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:25 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com