Thread: Row values
Hello, I am writing my first trigger in C for PostgreSQL. It compiles Ok, and added it to the database using CREATE TRIGGER. But when I try to fire it, psql simply says 'The connection was lost". What I don't know is how to get the row values (not the name fields) from tg_trigger. The code is: ... TriggerData *trigdata = (TriggerData *) fcinfo->context; ... strcpy(query, "INSERT INTO visita_log VALUES ('"); strcat(query, trigdata->tg_trigger->tgargs[0]); strcat(query, "','"); strcat(query, trigdata->tg_trigger->tgargs[1]); strcat(query, "','"); strcat(query, trigdata->tg_trigger->tgargs[2]); strcat(query, "','"); strcat(query, trigdata->tg_trigger->tgargs[3]); strcat(query, "',"); strcat(query, trigdata->tg_trigger->tgargs[4]); strcat(query, ",'"); strcat(query, trigdata->tg_trigger->tgargs[5]); strcat(query, "');"); SPI_exec(query, 0); ... I don't know if tgargs[] return the row values or the field names. Thanks. Juan
On Fri, Jul 02, 2004 at 07:36:50AM -0300, Juan Jose Costello Levien wrote: > I am writing my first trigger in C for PostgreSQL. It compiles Ok, and > added it to the database using CREATE TRIGGER. But when I try to fire > it, psql simply says 'The connection was lost". Most likely the server process crashed. See the server log and the core file for details to debug your function. -- Alvaro Herrera (<alvherre[a]dcc.uchile.cl>) La web junta la gente porque no importa que clase de mutante sexual seas, tienes millones de posibles parejas. Pon "buscar gente que tengan sexo con ciervos incendiánse", y el computador dirá "especifique el tipo de ciervo" (Jason Alexander)
Alvaro, Sorry, but, where are the log file and core you mentioned? I tried /var/log/postgresql but is in 0 file size. TIA >On Fri, Jul 02, 2004 at 07:36:50AM -0300, Juan Jose Costello Levien wrote: > > > >>I am writing my first trigger in C for PostgreSQL. It compiles Ok, and >>added it to the database using CREATE TRIGGER. But when I try to fire >>it, psql simply says 'The connection was lost". >> >> > >Most likely the server process crashed. See the server log and the core >file for details to debug your function. > > >
Juan Jose Costello Levien <jcostello@datafull.com> writes: > I don't know if tgargs[] return the row values or the field names. Neither --- it's the (fixed) arguments you used in the CREATE TRIGGER command. You'll need to do something involving extracting field values from the tuple that is passed to the trigger, instead. I'd suggest looking in the contrib/ modules for examples of triggers written in C. regards, tom lane
On Fri, Jul 02, 2004 at 09:56:43AM -0300, Juan Jose Costello Levien wrote: > Alvaro, > > Sorry, but, where are the log file and core you mentioned? I tried > /var/log/postgresql but is in 0 file size. Your server may be misconfigured (most linux distros are). Make sure your init script does not redirect postmaster's (or pg_ctl's) stdout/stderr to /dev/null. Also make sure that if you are using syslog, the syslog server is configured to save the messages somewhere useful, by checking the facility Postgres uses (configurable) and where does syslog save messages from this facility. The core file, on the other hand, should be somewhere in /var/lib/pgsql/data/base (if you haven't changed PGDATA), _unless_ the server runs under a core 0-byte limit (under bash, ulimit -c will tell you). Hope this helps, -- Alvaro Herrera (<alvherre[a]dcc.uchile.cl>) "Java is clearly an example of a money oriented programming" (A. Stepanov)