Re: plperl functions -- can they call each other?

From: "ayhan" <ayhan(at)drexel(dot)edu>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: plperl functions -- can they call each other?
Date: 2003-01-30 10:48:58
Message-ID: 000701c2c84d$34be02e0$a000a8c0@burgaz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

AFAIK, ==> the short answer is : No, not directly. As, apparently, the
language handler just makes these functions anonymous subroutines.

There are 2 ways that you can deal with this though (not counting the
possible SQL call via PgSPI).

A) If you are willing to switch to "plperlU" (the untrusted vesion) ---
with all the SECURITY and STABILITY implications (see the doc for that),
there is a way :

1) Define the subroutine in a perl module
2) Put the module in a directory that would be in the @INC.
3) "Use" that module in your plperlu "procedure". (which will
load it just once per backend).
4) And then just call the desired subroutine.

This has the added advantage that such subroutines are reusable not just
within pgSQL but anything that you do with Perl. Besides, this way you
wouldn't have to woory about the -very anoying- escaping backslashes and
doubling single quotes problem.

This is the normal Perlish way.

B) The other way is a very hairy hack with the symbol table. I don't
think you would even want to know.... In summary, this would mean
actually creating an anonymous subroutine within your proc, assigning it
a name in the symbol table if it hasn't been done already (by an earlier
call of your proc). And then using that name in your other procs.
Besides you would have to make sure that the code that magically adds
the subroutine to the symbol table gets executed BEFORE any calls to
that subroutine within any one session. UGLY. UGLY. UGLY. -- only if
you can't live with plperlu.

Hope this helps,
Ayhan

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org [
<mailto:pgsql-general-owner(at)postgresql(dot)org>
mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of will trillich
Sent: mercredi 29 janvier 2003 20:52
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] plperl functions -- can they call each other?

create or replace function to_partial_ymd(int2,int2,int2)returns int4 as
' my ($y,$m,$d) = @_; $m = 0 unless $y; $m = 0 unless 1 <= $m and $m <=
12; $d = 0 unless $m; $d = 0 unless (1 <= $d and
(
# 28 days valid for ANY month:
($d <= 28)
or
# 29 days valid if not february -- or in a leap year
($d <= 29 and ( $m != 2 or $y % 4 == 0 ))
or
# 30 days valid if not february
($d <= 30 and $m != 2)
or
# 31 days valid jan/mar/may/jul/aug/oct/dec
($d <= 31 and $m =~ /^(1|3|5|7|8|10|12)$/)
)
);
return ($y << 16) + ($m << 8) + ($d << 0);
' language 'plperl'; -- '

sure would be nice to have such hefty day-of-month logic just ONCE, and
be able to call it from other functions...

is there still no way for one plperl function to call another plperl
function? (i'm hoping that section 25.3.4 is out-of-date...)

--
There are 10 kinds of people:
ones that get binary, and ones that don't.

will(at)serensoft(dot)com
<http://sourceforge.net/projects/newbiedoc>
http://sourceforge.net/projects/newbiedoc -- we need your brain!
<http://www.dontuthink.com/> http://www.dontUthink.com/ -- your brain
needs us!

Looking for a firewall? Do you think smoothwall sucks? You're probably
right... Try the folks at <http://clarkconnect.org/>
http://clarkconnect.org/ !

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster


Browse pgsql-general by date

  From Date Subject
Next Message Peter Gibbs 2003-01-30 10:51:18 Re: 'GROUP BY' problem
Previous Message Manfred Koizar 2003-01-30 10:33:08 Re: mass import to table with unique index