Re: Newbie: help with FUNCTION

From: Rick Apichairuk <rapichai(at)gmail(dot)com>
To: Charl Gerber <charlgerber(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Newbie: help with FUNCTION
Date: 2005-02-26 02:24:13
Message-ID: 9776bb660502251824587de62d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> > On Thu, Feb 24, 2005 at 09:00:46PM +0000, Charl Gerber wrote:
> > I'm trying to create a function that takes 1
> > paramater (eg an integer) as input, then does 5
> > database updates or deletes in 5 different SQL
> > statements and returns 5 integers (in one resultset)
> > indicating how many rows were affected by the various
> > updates/deletes.
> >
> > How do I do this?

You could return an array like elein recommended....

> > How can I specify the names of the 5 output colums?

but you won't have "names" associated with the output columns. To have
something other than integers as the index (such as a string), you
need to use an associative array.

sub foo
{
my $integer = shift;

my $ret1 = $dbh->do('some sql here');

my $ret2 = $dbh->do('some sql here');

# etc.... for 5 statements.

my %hash = (
'Column Label 1' => $ret1,
'Column Label 2' => $ret2,
#..... etc...
);

return \%hash;
}

So, you should read about associative arrays (aka hashes) and references.

Rick

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Hall 2005-02-26 05:01:15 Re: Lost rows/data corruption?
Previous Message Tzahi Fadida 2005-02-26 02:17:46 SPI vs low level functions.