SP::Fn simplifies the use of PostgreSQL stored functions, in perl. Here's a slightly-abbreviated example.
   use SP::Fn;

   # Create a function object.
   my $fn = SP::Fn->new(name => 'my_stored_function');

   # Call the function and show something of its results.
   my $result = $fn->call($arg1, $arg2);
   printf("The call returned %d rows.\n", scalar(@{$result}));
The html-ized 'pod' for the module is here. It depends on perl 5.10.0+, Moose and DBD::Pg. The SP::Fn download includes a handy script for trying out SP::Fn on some sample functions. Here's the help for the script.
$ ./fn-test.pl --help
Usage: fn-test.pl OPTION...
Report on and optionally call a Postgresql stored function.

OPTIONS
   --call
        Call the function.
   --conninfo=STR
        Database connection string, as in the PQconnectdb function in
        libpq.  If omitted, connect to your default database.
   --name=NAME
        The name of the stored function.  Use this or --oid.
   --null
        An argument non-value, i.e. pass undef (perl) / NULL (SQL) for
        this argument.  Ignored if you omit '--call'.
   --oid=INT
        The postgres 'Object Identifier' for the function.  Use this
        or --name.
   --val=VAL
        An argument value to use in the call.  The value you supply is
        treated as a string literal and cast to the argument's type.
        The option is ignored if you omit '--call'.  Omitting =VAL is
        equivalent to ='', the empty string.  To pass undef (NULL),
        see '--null'.
   --verbose
        Print more messages.  Repeat for more verbosity.
   --help
        Print this help.

Use --val (or --null) zero or more times to specify the argument
values for your call; they will be passed in the order you use them.

Example

   fn-test.pl --name="myfunc" --call --val=27 --null --val

calls the stored function myfunc with three arguments, the first
having the value '27', the second NULL and the third the empty string.

   fn-test.pl --conninfo="host=gallifrey dbname=dalek" \
      --name="f7" --call --val='{"abc","def"}'

calls f7 with one argument, an array containing two strings.
Your comments welcome at webmaster@acrasis.net.

Words

Pictures

Updated 2010-11-06 00:23 GMT