Adam Sjøgren wrote:
  Hi.


Enclosed is a tiny patch for plperl that puts the schema-name of the
current table in $_TD, so triggers can access tables using
schemaname.tablename, for instance like so:

 my $query='INSERT INTO ' . $_TD->{nspname} . '.' . $_TD->{relname} . '_archive 
(' . $fieldnames . ') VALUES(' . $values . ');';

(This way my triggers can work without setting search_path).

The patch was made against PostgreSQL 8.1.3 in Ubuntu dapper.


This is my first patch for PostgreSQL, so any advice, comments,
pointers, etc. are very welcome.

Patches should be made against the HEAD branch in CVS, not against a distro source.

This seems like a good idea, but we should probably make analogous changes for plpgsql, pltcl and plpython. Having different trigger data available in some of these doesn't seem like a good idea.

cheers

andrew




  Best regards,

    Adam


*** src/pl/plperl/plperl.c.orig 2006-05-23 16:57:25.000000000 +0200
--- src/pl/plperl/plperl.c      2006-05-23 16:57:45.000000000 +0200
***************
*** 550,555 ****
--- 550,558 ----
        hv_store(hv, "relname", 7,
                         newSVpv(SPI_getrelname(tdata->tg_relation), 0), 0);
+ hv_store(hv, "nspname", 7,
+                          newSVpv(SPI_getnspname(tdata->tg_relation), 0), 0);
+ if (TRIGGER_FIRED_BEFORE(tdata->tg_event))
                when = "BEFORE";
        else if (TRIGGER_FIRED_AFTER(tdata->tg_event))
*** doc/src/sgml/plperl.sgml.orig       2006-05-24 10:06:02.000000000 +0200
--- doc/src/sgml/plperl.sgml    2006-05-24 10:05:49.000000000 +0200
***************
*** 675,680 ****
--- 675,689 ----
      </varlistentry>
<varlistentry>
+      <term><literal>$_TD-&gt;{nspname}</literal></term>
+      <listitem>
+       <para>
+        Name of the schema in which the table on which the trigger fired, is
+       </para>
+      </listitem>
+     </varlistentry>
+ + <varlistentry>
       <term><literal>$_TD-&gt;{argc}</literal></term>
       <listitem>
        <para>

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



---------------------------(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

Reply via email to