plperl - put schema-name in $_TD - Mailing list pgsql-patches

From Adam Sjøgren
Subject plperl - put schema-name in $_TD
Date
Msg-id 7plksrzv6k.fsf@sille.nzcorp.net
Whole thread Raw
Responses Re: plperl - put schema-name in $_TD  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-patches
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.


  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->{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->{argc}</literal></term>
       <listitem>
        <para>

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [GENERAL] Querying libpq compile time options
Next
From: Zdenek Kotala
Date:
Subject: Allow commenting of variables in postgresql.conf to restore them to defaults