Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Sam Mason
On Tue, Dec 04, 2007 at 10:11:04AM -0600, Glen W. Mabey wrote: > Searching for DatumGetTextP from the search text box at the top of > www.postgresql.org yields no hits, and a google search on DatumGetTextP > does not seem to turnip [sic] any direct documentation on this function. > > Is there som

Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Tom Lane
"Glen W. Mabey" <[EMAIL PROTECTED]> writes: > On Tue, Dec 04, 2007 at 09:53:37AM -0600, Tom Lane wrote: >> 3. You're not checking for a null, and the error check you do have >> is wrong/redundant. > The field is constrained to be NOT NULL, so I wasn't worried about > checking that, but I don't see

Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Glen W. Mabey
On Tue, Dec 04, 2007 at 09:53:37AM -0600, Tom Lane wrote: > "Glen W. Mabey" <[EMAIL PROTECTED]> writes: > > Is there somewhere that I am not adequately checking for an error? > > 1. You're passing SPI_getbinval an uninitialized bool pointer. Doh! > 2. You're discarding its result, which you ne

Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Martijn van Oosterhout
On Tue, Dec 04, 2007 at 09:26:46AM -0600, Glen W. Mabey wrote: > On Tue, Dec 04, 2007 at 09:10:21AM -0600, Pavel Stehule wrote: > > use macro DatumGetPointer(datum) > > When I do that, I get the following compiler warning: > > warning: assignment from incompatible pointer type Well yes, you'

Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Tom Lane
"Glen W. Mabey" <[EMAIL PROTECTED]> writes: > Is there somewhere that I am not adequately checking for an error? 1. You're passing SPI_getbinval an uninitialized bool pointer. 2. You're discarding its result, which you need. 3. You're not checking for a null, and the error check you do have i

Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Alvaro Herrera
Glen W. Mabey escribió: > TriggerData *trigdata; > Datum relative_filename_datum; > text *relative_filename_t; > int file_name_colnumber, ret; > bool *isnull; This is wrong. Try bool isnull; and later: SPI_getbinval( trigdata->tg_trigtuple, trigdata->tg_rel

Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Glen W. Mabey
On Tue, Dec 04, 2007 at 09:10:21AM -0600, Pavel Stehule wrote: > use macro DatumGetPointer(datum) When I do that, I get the following compiler warning: warning: assignment from incompatible pointer type which is what originally motivated me to look for another means, which led me to use PG_D

Re: [GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Pavel Stehule
On 04/12/2007, Glen W. Mabey <[EMAIL PROTECTED]> wrote: > 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 c

[GENERAL] difficulty extracting variable-sized field on triggered row

2007-12-04 Thread Glen W. Mabey
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 tex