Patch for PLPYTHONU - adding TD["relname"] - Mailing list pgsql-patches

From Sokolov Yura
Subject Patch for PLPYTHONU - adding TD["relname"]
Date
Msg-id 43423C3E.1010809@intercable.ru
Whole thread Raw
Responses Re: Patch for PLPYTHONU - adding TD["relname"]
Re: Patch for PLPYTHONU - adding TD["relname"]
List pgsql-patches
Excuse my English.
Patch allows to get triggers table name in the trigger TD['relname'].
Usefull when same trigger function applied to different tables.
patch for plpython.c in Postgres 8.1 beta (diff was applied to)
works also in Postgres 8.0.3 when placed in the same function (may be
different line numbers)

--- plpython-old.c    2005-07-10 08:56:55.000000000 +0400
+++ plpython.c    2005-10-04 12:03:36.000000000 +0400
@@ -582,7 +582,8 @@ PLy_trigger_build_args(FunctionCallInfo
                *pltevent,
                *pltwhen,
                *pltlevel,
-               *pltrelid;
+               *pltrelid,
+               *pltrelname;
     PyObject   *pltargs,
                *pytnew,
                *pytold;
@@ -606,6 +607,12 @@ PLy_trigger_build_args(FunctionCallInfo
         Py_DECREF(pltrelid);
         pfree(stroid);

+        stroid = SPI_getrelname(tdata->tg_relation);
+        pltrelname = PyString_FromString(stroid);
+        PyDict_SetItemString(pltdata, "relname", pltrelname);
+        Py_DECREF(pltrelname);
+        pfree(stroid);
+
         if (TRIGGER_FIRED_BEFORE(tdata->tg_event))
             pltwhen = PyString_FromString("BEFORE");
         else if (TRIGGER_FIRED_AFTER(tdata->tg_event))



pgsql-patches by date:

Previous
From: Euler Taveira de Oliveira
Date:
Subject: Re: Translation updates: pt_BR
Next
From: Peter Eisentraut
Date:
Subject: Re: Translation updates: pt_BR