pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Accessing insert values in triggers
2+ messages / 2 participants
[nested] [flat]

* Accessing insert values in triggers
@ 2005-02-02 10:02  Hasnul Fadhly bin Hasan <hasnulfadhly.h@mimos.my>
  0 siblings, 1 reply; 2+ messages in thread

From: Hasnul Fadhly bin Hasan @ 2005-02-02 10:02 UTC (permalink / raw)
  To: pgsql-performance; pgsql-novice@postgresql.org

Hi,

I am trying to build a function that would extend the trigger in general 
tid bits that would only track count changes for table rows.

The one i am trying to build would check which column and value should 
be tracked.

e.g. below would be the tracker.

CREATE TABLE "public"."aaaa" (
  "tables" TEXT,
  "columns" TEXT[],
  "values" TEXT[],
  "counts" BIGINT
) WITH OIDS;

The column array is the column name and the values array would be the 
values matching the columns array defined.

if columns has {group,item} then values has {1,'basket'} so if the data 
inserted matches the values defined, it will be tracked.

When new data is inserted, we have to use new.xxxx to access the data.  
Is there another way to access the data that would be more generic
like value[1] and so on?  This way, the tracker is independant of any 
tables.  i believe tg_argv is only for data being updated.

I'm have not done any functions in C, but for those who has, it is more 
possible to do it in C?  If those who has used it say i can access the 
data easier
in C, then i'll have to read up and learn it.

I was looking through the examples in the doc on creating triggers in 
C.  I believe the data i'm looking for is in tg_trigtuple but i am not 
sure how it is supposed to be accessed.  Anyone knows of any links i can 
refer to or anyones has simple codes showing how to access the data?

Thanks for any info.

Hasnul









^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [PERFORM] Accessing insert values in triggers
@ 2005-02-03 08:01  Michael Fuhr <mike@fuhr.org>
  parent: Hasnul Fadhly bin Hasan <hasnulfadhly.h@mimos.my>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Fuhr @ 2005-02-03 08:01 UTC (permalink / raw)
  To: Hasnul Fadhly bin Hasan <hasnulfadhly.h@mimos.my>; +Cc: pgsql-performance; pgsql-novice@postgresql.org

On Wed, Feb 02, 2005 at 06:02:28PM +0800, Hasnul Fadhly bin Hasan wrote:

> When new data is inserted, we have to use new.xxxx to access the data.  
> Is there another way to access the data that would be more generic
> like value[1] and so on?  This way, the tracker is independant of any 
> tables.

Procedural languages like PL/Perl, PL/Tcl, and PL/Python can access
NEW and OLD columns without knowing the column names in advance.

http://www.postgresql.org/docs/8.0/static/plperl-triggers.html
http://www.postgresql.org/docs/8.0/static/pltcl-trigger.html
http://www.postgresql.org/docs/8.0/static/plpython-trigger.html

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-02-03 08:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-02 10:02 Accessing insert values in triggers Hasnul Fadhly bin Hasan <hasnulfadhly.h@mimos.my>
2005-02-03 08:01 ` Michael Fuhr <mike@fuhr.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox