Home > Archive > PostgreSQL Discussion > April 2006 > Running Command Line From Trigger?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Running Command Line From Trigger?
Yudie Pg

2006-04-06, 8:25 pm

I want to execute a command line from trigger function.
The reason is I want to execute my perl script from stored procedure.

any idea?


Yudie

Scott Marlowe

2006-04-06, 8:25 pm

On Thu, 2006-04-06 at 14:48, Yudie Pg wrote:
> I want to execute a command line from trigger function.
> The reason is I want to execute my perl script from stored procedure.
>


Why not just install perl as a procedural language? It's one of a dozen
or more available to you. Then you can write the whole trigger in perl
instead of calling an external program.

Note that perl, like many other languages, is available in a "trusted"
and an "untrusted" version. The trusted versions aren't allowed to do
dangerous things like access the file system and run external programs.
Untrusted will do anything that perl can do from the command line.

Note that plpgsql cannot run external programs on purpose. It's a
security and safety issue.

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

Terry Lee Tucker

2006-04-06, 8:25 pm


On Thursday 06 April 2006 03:48 pm, Yudie Pg saith:
> I want to execute a command line from trigger function.
> The reason is I want to execute my perl script from stored procedure.
>
> any idea?
>
>
> Yudie


Yudie,

You might want to write your perl script as a trusted perl funcion and call
from your trigger as you would any other backend function.

Example of one we use:

CREATE OR REPLACE FUNCTION fmtstr (TEXT, INTEGER) RETURNS TEXT AS '
my ($str, $len) = @_;
return (pack ("A$len", $str));
' LANGUAGE 'plperlu';

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

Yudie Pg

2006-04-07, 11:27 am

>
>


I'm running postgresql 7.4.1. is it can't really be used for trigger
function?

http://www.postgresql.org/docs/7.4/...rl-missing.html

Scott Marlowe

2006-04-07, 11:27 am

On Fri, 2006-04-07 at 10:42, Yudie Pg wrote:
>
>
> I'm running postgresql 7.4.1. is it can't really be used for trigger
> function?
>
> http://www.postgresql.org/docs/7.4/...rl-missing.html
>


Two points:

1: Upgrade to 7.4.12 (or whatever the latest version is) immediately.
There are known data loss bugs in 7.4.1, and usually, the closer you are
to 7.4.0, the more likely those kinds of bugs are to show up. I.e. a
data loss bug discovered in 7.4.11 and fixed in 7.4.12 is probably
REALLY rare, but one found in 7.4.0 and fixed in 7.4.2 is much more
likely to be a common occurrence, since those are found early on.

2: Try using plphp. It can be used for triggers. So can pltcl if
you'd rather use that.

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Scott Marlowe

2006-04-07, 11:27 am

On Fri, 2006-04-07 at 10:42, Yudie Pg wrote:
>
>
> I'm running postgresql 7.4.1. is it can't really be used for trigger
> function?
>
> http://www.postgresql.org/docs/7.4/...rl-missing.html
>


Quick followup, the latest plPHP does not work on Postgresql versions <
8.0. So you'd either need to upgrade your postgresql to run it, or look
for pltcl. pltcl has been around a while, so I can't imagine there not
being a good, solid, working version for pg 7.4

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Tony Caduto

2006-04-07, 11:27 am

Yudie Pg wrote:
>
>
>
> I'm running postgresql 7.4.1. is it can't really be used for trigger
> function?
>
> http://www.postgresql.org/docs/7.4/...rl-missing.html
>
>
>
>
>

That is true, but you can call a plperl function from a plpgsql trigger
function.
Wouldn't that work?

--
Tony Caduto
AM Software Design
http://www.amsoftwaredesign.com
Home of PG Lightning Admin for Postgresql
Your best bet for Postgresql Administration


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Yudie Pg

2006-04-07, 1:28 pm

Back to my original question where is it possible to run a command line from
a function?

Terry Lee Tucker

2006-04-07, 1:28 pm

On Friday 07 April 2006 01:32 pm, Yudie Pg saith:
> Back to my original question where is it possible to run a command line
> from a function?


From an earlier post:
"Note that plpgsql cannot run external programs on purpose. It's a
security and safety issue."

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Scott Marlowe

2006-04-07, 1:28 pm

On Fri, 2006-04-07 at 12:38, Terry Lee Tucker wrote:
> On Friday 07 April 2006 01:32 pm, Yudie Pg saith:
>
> From an earlier post:
> "Note that plpgsql cannot run external programs on purpose. It's a
> security and safety issue."


Which is why I had advised using another language. Help! We're all
trapped in a loop! ahhhhhhhhhhhhhhh!

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql
.org so that your
message can get through to the mailing list cleanly

Terry Lee Tucker

2006-04-07, 1:28 pm

Reminds me of an old Star Trek - Next Generation episode. They were stuck in a
time loop reliving the same series of events over and over. They had to leave
themselves a clue so they could figure it out next time around. Maybe your
post is it ;o)

On Friday 07 April 2006 02:12 pm, Scott Marlowe saith:
> On Fri, 2006-04-07 at 12:38, Terry Lee Tucker wrote:
>
> Which is why I had advised using another language. Help! We're all
> trapped in a loop! ahhhhhhhhhhhhhhh!
>


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Yudie Pg

2006-04-07, 8:25 pm

Help!
Try to install plperl
../createlang plperl mydb

createlang: language installation failed: ERROR: could not access file
"$libdir/plperl": No such file or directory

Terry Lee Tucker

2006-04-07, 8:25 pm


On Friday 07 April 2006 03:52 pm, Yudie Pg saith:
> Help!
> Try to install plperl
> ./createlang plperl mydb
>
> createlang: language installation failed: ERROR: could not access file
> "$libdir/plperl": No such file or directory


Do you have the Perl module on your machine? If not, you can get it here:
http://search.cpan.org/search?query=Pg&mode=all

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com