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); } } ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq