difficulty extracting variable-sized field on triggered row

From: "Glen W(dot) Mabey" <Glen(dot)Mabey(at)swri(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: difficulty extracting variable-sized field on triggered row
Date: 2007-12-04 14:43:42
Message-ID: 20071204144342.GB14370@bams.ccf.swri.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I have been trying to write a trigger in C operating on each row
that would (as a first step) copy a field of type TEXT into a text*
variable.

I think that I've got the SPI_connect, SPI_fnumber, and SPI_getbinval
calls correct, but this gives me a Datum.

How do I convert a Datum to a text*?

The following is the best I could do, and it segfaults ...

Thank you,
Glen Mabey

if( CALLED_AS_TRIGGER( fcinfo ) ) {
elog(INFO, "unlink_file was called as a trigger." );
trigdata = (TriggerData *) fcinfo->context;

if( ( ret = SPI_connect() ) != SPI_OK_CONNECT ) {
elog(INFO, "SPI_connect returned %d", ret);
}

file_name_colnumber = SPI_fnumber( trigdata->tg_relation->rd_att, "file_name" );

if( file_name_colnumber == SPI_ERROR_NOATTRIBUTE ) {
elog(INFO, "SPI_fnumber returned SPI_ERROR_NOATTRIBUTE" );
}

SPI_getbinval( trigdata->tg_trigtuple, trigdata->tg_relation->rd_att, file_name_colnumber, isnull );
relative_filename_t = PG_DETOAST_DATUM( relative_filename_datum );

if( SPI_result == SPI_ERROR_NOATTRIBUTE ) {
elog(INFO, "SPI_fnumber returned SPI_ERROR_NOATTRIBUTE" );
}

if( ( ret = SPI_finish() ) != SPI_OK_FINISH ) {
elog(INFO, "SPI_finish returned %d", ret);
}
}

Responses

Browse pgsql-general by date

  From Date Subject
Next Message SHARMILA JOTHIRAJAH 2007-12-04 14:55:15 WAL shipping question
Previous Message Raymond O'Donnell 2007-12-04 14:01:01 Re: 1 cluster on several servers