Triggers cause backend crash - Mailing list pgsql-bugs

From Andras Belokosztolszki
Subject Triggers cause backend crash
Date
Msg-id F135wrblZz02H67yRLV000163ae@hotmail.com
Whole thread Raw
Responses Re: Triggers cause backend crash  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
/*
* Andras Belokosztolszki
*
* A trigger function invoked when a predicate is is modified
* it looks up in the registered templates for this predicate the
* parties to be notified

*
* create trigger t4predt_..._trigger
*       AFTER INSERT on ...
*       FOR EACH ROW
*       EXECUTE PROCEDURE t4predt_trig1();
*
*/



#include "executor/spi.h"    /* this is what you need to work with SPI */
#include "commands/trigger.h"    /* -"- and triggers */

#include "catalog/pg_type.h"    /* for OID constants */

#include "MPS_triggers.h"

extern Datum t5_pred_general_trig(PG_FUNCTION_ARGS) ;

Datum t5_pred_general_trig(PG_FUNCTION_ARGS) {
  TriggerData *trigdata = (TriggerData *) fcinfo->context;

  TupleDesc    tupdesc1;
  HeapTuple    rettuple;
  HeapTuple    rettuple_old;      /* in case of update the old tuple */
  Relation      rel;

  Trigger       *trigger;          /* to get trigger name */
  int           nargs;
  char          **args;            /* arguments */

  elog(NOTICE, "PredicateGeneralTrigger: Called");

  if (!CALLED_AS_TRIGGER(fcinfo))
    elog(ERROR, "PredicateGeneralTrigger: not fired by trigger manager!");

  /* tuple to return */
  if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event)) {
    rettuple = trigdata->tg_newtuple;
    rettuple_old = trigdata->tg_trigtuple;
  } else {
    rettuple = trigdata->tg_trigtuple;
    rettuple_old = trigdata->tg_trigtuple; // old tuple is the default !!!
  }

  if (!TRIGGER_FIRED_AFTER(trigdata->tg_event)) {
    elog(ERROR,"PredicateGeneralTrigger: Trigger not fired after event");
  }

  rel = trigdata->tg_relation;
  tupdesc1 = trigdata->tg_relation->rd_att;

  // check trigger parameters !!
  trigger = trigdata->tg_trigger;
  nargs = trigger->tgnargs;
  args = trigger->tgargs;

  trigdata = NULL;

  /* connect to the database */
  SPI_connect();
  SPI_finish();
  elog(NOTICE,"General trigger finished");
  return PointerGetDatum(rettuple);
}

pgsql-bugs by date:

Previous
From: pgsql-bugs@postgresql.org
Date:
Subject: Bug #503: case and LIMIT not working together
Next
From: pgsql-bugs@postgresql.org
Date:
Subject: Bug #504: multiple cursors cause transaction problems