Re: Newbie: help with FUNCTION

Поиск
Список
Период
Сортировка
От Rick Apichairuk
Тема Re: Newbie: help with FUNCTION
Дата
Msg-id 9776bb660502251824587de62d@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Newbie: help with FUNCTION  (elein@varlena.com (elein))
Список 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

В списке pgsql-general по дате отправления:

Предыдущее
От: Tzahi Fadida
Дата:
Сообщение: SPI vs low level functions.
Следующее
От: Greg Stark
Дата:
Сообщение: Re: row numbering