Trigger question - Mailing list pgsql-hackers

From Mitch Vincent
Subject Trigger question
Date
Msg-id 01e901bfe071$788e9640$0300000a@doot.org
Whole thread Raw
List pgsql-hackers
This is a bit off topic but email to the author of the trigger bounced..

In the fti.c (full text index) trigger I see..

sprintf(query, "INSERT INTO %s (string, id) VALUES ($1, $2)", indexname);

below.. I need to add something else here.. Basically I'm eliminating the
need for the text table, I'm going to integrate the fti indexed table into
an existing one I have but I need to insert naother ID into the resumes_fti
(my indexed fti table)..

The above makes the query string, as I can see but what in the world is the
$1 $2 and where did they come from? Since it looks like that's how the
values of string and id are put into the query, I need to know so I can add
one more in there..

Below is the whole function I'm referring to in fti.c

Thanks!!!


if (isinsert){ char    *substring,      *column; void    *pplan; Oid     *argtypes; Datum  values[2]; int   colnum;
structvarlena *data; EPlan    *plan;
 
 sprintf(query, "I%s$%s", args[0], args[1]); plan = find_plan(query, &InsertPlans, &nInsertPlans);
 /* no plan yet, so allocate mem for argtypes */ if (plan->nplans <= 0) {  argtypes = (Oid *) palloc(2 * sizeof(Oid));
  argtypes[0] = VARCHAROID; /* create table t_name (string          * varchar, */  argtypes[1] = OIDOID;  /* id   oid);
  */
 
  /* prepare plan to gain speed */  sprintf(query, "INSERT INTO %s (string, id) VALUES ($1, $2)",    indexname);  pplan
=SPI_prepare(query, 2, argtypes);  if (!pplan)   elog(ERROR, "Full Text Indexing: SPI_prepare returned NULL "     "in
insert");
  pplan = SPI_saveplan(pplan);  if (pplan == NULL)   elog(ERROR, "Full Text Indexing: SPI_saveplan returned NULL"     "
ininsert");
 
  plan->splan = (void **) malloc(sizeof(void *));  *(plan->splan) = pplan;  plan->nplans = 1; }





pgsql-hackers by date:

Previous
From: "Grigori Soloviov"
Date:
Subject: Any Documentation on PL/pgSQL?
Next
From: Stephan Szabo
Date:
Subject: Re: Proposal: More flexible backup/restore via pg_dump