From: | "Jasbinder Singh Bali" <jsbali(at)gmail(dot)com> |
---|---|
To: | "Harpreet Dhaliwal" <harpreet(dot)dhaliwal01(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Dynamic loading of Perl Code in Postgres functions |
Date: | 2007-01-19 14:41:50 |
Message-ID: | a47902760701190641s64893dc2v4729928b1c69356d@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thats exactly what I'm facing here.
CREATE OR REPLACE FUNCTION test(int4)
RETURNS int4 AS
$BODY$
require "abc.pl"
$BODY$
LANGUAGE 'plperlu' VOLATILE;
SELECT test(23) doesn't run the script inside abc.pl that happens to
be a some insert statements.
Now, when i actually copy and paste the script of abc.pl inside the
postgres function body and then do SELECT test(23) it works fine by
executing those insert statements.
Don't know whats wrong here now.
Can anyone please throw some light on it.
Thanks,
Jas
On 1/18/07, Harpreet Dhaliwal <harpreet(dot)dhaliwal01(at)gmail(dot)com> wrote:
> Don't think it would work the way you are doing it.
> This way it would only work if you dealing with shared objects in C where in
> you dynamically load the shared object and then call a specific function of
> that shared object.
>
> Lately i tried the following for you but it doesn't execute the Insert
> script inside sql.pl
>
> CREATE OR REPLACE FUNCTION test_perl_param(int4)
> RETURNS bool AS
> $BODY$
> require "/usr/local/pgsql/jsbali/sql.pl"
> $BODY$
> LANGUAGE 'plperlu' VOLATILE;
> ALTER FUNCTION test_perl_param(int4) OWNER TO postgres;
>
> SELECT test_perl_param(23)
>
> Here in sql.pl i have one insert statement but SELECT test_perl_param(23)
> doesn't run the INSERT statement inside the sql.pl
>
> Can anyone throw light on how to make it work so that whatever script i have
> inside sql.pl run as soon as I run SELECT test_perl_param(23).
>
> I think this wold help out jas alot.
>
> Thanks,
> Harpreet
>
>
> On 1/18/07, Jasbinder Singh Bali <jsbali(at)gmail(dot)com> wrote:
> >
> > Lately i've been able to user 'require' command successfully and the
> > script was pretty straight forward and simple. I had to play around
> > with @INC.
> >
> > Moving forward, I have another question here,
> >
> > CREATE FUNCTION *funcname* (*argument-types*) RETURNS *return-type* AS
> > require " abc.pl"
> > $$ LANGUAGE plperlu;
> >
> > In the above script if I have to call a particular sub-routine in abc.pl.
> > How can that be done?
> > I have to pass values to the arguments of a sub routine in abc.pl from
> > the the function funcname (arguments of the funcname in particular).
> > How would this thing be done?
> >
> > Thanks,
> > Jas
> >
> > On 1/16/07, Harpreet Dhaliwal < harpreet(dot)dhaliwal01(at)gmail(dot)com> wrote:
> > > so my syntax is correct? just wondering if there's some fundamental
> mistake
> > > in it
> > > ~Harpreet
> > >
> > >
> > > On 1/16/07, Tom Lane < tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > > > "Harpreet Dhaliwal" < harpreet(dot)dhaliwal01(at)gmail(dot)com > writes:
> > > > > I was just wondering if one could use something like this
> > > >
> > > > > CREATE FUNCTION *funcname* (*argument-types*) RETURNS *return-type*
> AS
> > > $$
> > > > > require " abc.pl"
> > > > > $$ LANGUAGE plperl;
> > > >
> > > > You'd have to use plperlu, since "require" isn't considered a trusted
> > > > operation.
> > > >
> > > > > To include abc.pl here, how is the path of abc.pl specified.
> > > >
> > > > Same as you'd do it in plain Perl.
> > > >
> > > > regards, tom lane
> > > >
> > >
> > >
> >
> > ---------------------------(end of
> broadcast)---------------------------
> > TIP 6: explain analyze is your friend
> >
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2007-01-19 14:43:48 | Re: Spam from EnterpriseDB? |
Previous Message | Martijn van Oosterhout | 2007-01-19 14:33:12 | Re: Clearing plans |