Skip site navigation (1) Skip section navigation (2)

plperl - put schema-name in $_TD

From: Adam Sjøgren <adsj(at)novozymes(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: plperl - put schema-name in $_TD
Date: 2006-05-24 08:25:07
Message-ID: 7plksrzv6k.fsf@sille.nzcorp.net (view raw or flat)
Thread:
Lists: 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-&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>

Responses

pgsql-patches by date

Next:From: Zdenek KotalaDate: 2006-05-24 13:28:26
Subject: Allow commenting of variables in postgresql.conf to restore them to defaults
Previous:From: Bruce MomjianDate: 2006-05-23 22:13:06
Subject: Re: [GENERAL] Querying libpq compile time options

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group