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

Re: plperl - put schema-name in $_TD

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Adam Sjøgren <adsj(at)novozymes(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org
Subject: Re: plperl - put schema-name in $_TD
Date: 2006-05-24 14:12:17
Message-ID: 447469C1.8020804@dunslane.net (view raw or flat)
Thread:
Lists: pgsql-patches
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
>
>   


In response to

Responses

pgsql-patches by date

Next:From: Zdenek KotalaDate: 2006-05-24 14:14:52
Subject: Re: Allow commenting of variables in postgresql.conf to
Previous:From: Andrew DunstanDate: 2006-05-24 14:01:45
Subject: Re: Allow commenting of variables in postgresql.conf to

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