472,354 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

PL/Perl Trigger Problem

I'm new to Postgres, and getting nowhere with a PL/Perl trigger that
I'm trying to write - hopefully, someone can give me some insight into
what I'm doing wrong. My trigger is designed to reformat /
standardize phone numbers and it looks like this:
CREATE or REPLACE FUNCTION fixphone() RETURNS trigger AS $$
$number .= $_TD->{new}{phone};
$number =~ s/(-|\.|\(|\)| )//g;
$number .= substr($number,0,3) . "." .
substr($number,3,3) . "." .
substr($number,6,4);
$_TD->{new}{phone} .= $number;

return "MODIFY";
$$ LANGUAGE plperl;

CREATE TRIGGER "cust_fixphone" BEFORE INSERT OR UPDATE ON customer
FOR EACH ROW EXECUTE PROCEDURE "fixPhone"();

CREATE TRIGGER "vend_fixphone" BEFORE INSERT OR UPDATE ON vendor
FOR EACH ROW EXECUTE PROCEDURE "fixPhone"();
All I see in my web app, when the trigger fires, is:
DBD::Pg::db do failed: server closed the connection unexpectedly
And, when I try to update a row in psql I see:
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
Any help would truly be appreciated. Thanks in advance
Dunc
Jul 19 '05 #1
1 4072
At some point in time, go****@dunc-it.com (Dunc) wrote:
I'm new to Postgres, and getting nowhere with a PL/Perl trigger that
I'm trying to write - hopefully, someone can give me some insight into
what I'm doing wrong. My trigger is designed to reformat /
standardize phone numbers and it looks like this:
CREATE or REPLACE FUNCTION fixphone() RETURNS trigger AS $$
$number .= $_TD->{new}{phone};
$number =~ s/(-|\.|\(|\)| )//g;
$number .= substr($number,0,3) . "." .
substr($number,3,3) . "." .
substr($number,6,4);
$_TD->{new}{phone} .= $number;

return "MODIFY";
$$ LANGUAGE plperl;

On 12 Aug 2004 06:44:59 -0700, in comp.databases.postgresql.questions,
go****@dunc-it.com (Dunc) wrote:
I'm new to Postgres, and getting nowhere with a PL/Perl trigger that
I'm trying to write - hopefully, someone can give me some insight into
what I'm doing wrong. My trigger is designed to reformat /
standardize phone numbers and it looks like this:
CREATE or REPLACE FUNCTION fixphone() RETURNS trigger AS $$
$number .= $_TD->{new}{phone};
$number =~ s/(-|\.|\(|\)| )//g;
$number .= substr($number,0,3) . "." .
substr($number,3,3) . "." .
substr($number,6,4);
$_TD->{new}{phone} .= $number;

return "MODIFY";
$$ LANGUAGE plperl;


You're returning the wrong value. From section 35.1 of the 7.4.3 documentation:

Trigger functions return a table row (a value of type HeapTuple) to the calling
executor. A trigger fired before an operation has the following choices:

* It can return a NULL pointer to skip the operation for the current row
(and so the row will not be inserted/updated/deleted).
* For INSERT and UPDATE triggers only, the returned row becomes the row that
will be inserted or will replace the row being updated. This allows the trigger
function to modify the row being inserted or updated.

A before trigger that does not intend to cause either of these behaviors must be
careful to return as its result the same row that was passed in (that is, the
NEW row for INSERT and UPDATE triggers, the OLD row for DELETE triggers).

So you must return either "undef" to indicate that the row operation is to
discard the insert/update, or (in your case) one of $_TD->{new} or $_TD->{old}.
--
Jeff Boes vox 269.226.9550 ext 24
Database Engineer fax 269.349.9076
Nexcerpt, Inc. http://www.nexcerpt.com
...Nexcerpt... Extend your Expertise
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: joy | last post by:
I am writting a trigger, I have table parts(PNO,..,QOH,..), before delete the PNO row, I need to check QOH. Part of the trigger code like: create or replace trigger parts_bef_del_row before...
0
by: Sean Utt | last post by:
Table "grps" Column | Type | Modifiers -------------+-----------------------------+-------------------------------- --------------------- grpsid ...
3
by: Daniel Moree | last post by:
I'm attempting to use a perl script to interface with my Visual Basic 6 program using Winsock. I've got my program setup to connect and works great if i connect to another winsock program, but it...
4
by: SUKRU | last post by:
Hello everybody. Unfortunately I am pretty new to sql-server 2000 I need some help with a Trigger I created. I created a trigger witch takes the id of the affected row and does a update on a...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
3
by: pvpkumar | last post by:
Getting a trigger problem in SQL. As the table grows the trigger stops working. Upon reinstallation of SQL the trigger starts working. The problem was encountered for the following database/table...
8
by: Benzine | last post by:
Hi, I have an issue with my replication at the moment. I will try to describe the scenario accurately. I am using MS SQL 2000 SP4 with Merge Replication. Subscribers connect to the publisher...
2
by: dean.cochrane | last post by:
I have inherited a large application. I have a table which contains a hierarchy, like this CREATE TABLE sample_table( sample_id int NOT NULL parent_sample_id int NOT NULL ....lots of other...
7
by: Wojto | last post by:
Hello! Another day, another problem... :-) I've got something like this: CREATE TABLE A ( pk_A INT CONSTRAINT primarykey_A PRIMARY KEY ); CREATE TABLE B (
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.