Search Postgresql Archives

Re: Newbie: help with FUNCTION

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > 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

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux