Examing cotets of NEW & OLD in a function programed in perl

Started by stanabout 6 years ago4 messagesgeneral
Jump to latest
#1stan
stanb@panix.com

I need to write a generic function to process data before allowing the
insert or update to continue.

To do this, I need to be able to examine the NEW, and OLD structures
without prior knowledge of the structure of the table that fired the
trigger.

Can someone show me an example of how to get these structures into
something I can work with in Perl?

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: stan (#1)
Re: Examing cotets of NEW & OLD in a function programed in perl

stan <stanb@panix.com> writes:

I need to write a generic function to process data before allowing the
insert or update to continue.
To do this, I need to be able to examine the NEW, and OLD structures
without prior knowledge of the structure of the table that fired the
trigger.

AFAIR, they're just hashes in Perl, so you should be able to do
stuff like iterating over the hash keys.

regards, tom lane

#3stan
stanb@panix.com
In reply to: Tom Lane (#2)
Re: Examing cotets of NEW & OLD in a function programed in perl

On Tue, Mar 03, 2020 at 12:59:00PM -0500, Tom Lane wrote:

stan <stanb@panix.com> writes:

I need to write a generic function to process data before allowing the
insert or update to continue.
To do this, I need to be able to examine the NEW, and OLD structures
without prior knowledge of the structure of the table that fired the
trigger.

AFAIR, they're just hashes in Perl, so you should be able to do
stuff like iterating over the hash keys.

regards, tom lane

So, they should just be visible as OLD, and NEW as hasshes?

Sorry for my lack of understnading.

--
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
-- Benjamin Franklin

#4Christophe Pettus
xof@thebuild.com
In reply to: stan (#3)
Re: Examing cotets of NEW & OLD in a function programed in perl

On Mar 3, 2020, at 13:26, stan <stanb@panix.com> wrote:
So, they should just be visible as OLD, and NEW as hasshes?

They're documented here:

https://www.postgresql.org/docs/current/plperl-triggers.html

A global hash variable $_TD is available in the trigger function with all sorts of trigger-related info.

--
-- Christophe Pettus
xof@thebuild.com