Re: difficulty extracting variable-sized field on triggered row

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "Glen W(dot) Mabey" <Glen(dot)Mabey(at)swri(dot)org>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: difficulty extracting variable-sized field on triggered row
Date: 2007-12-04 15:43:51
Message-ID: 20071204154350.GB19536@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 getting a (void*) which you need to cast to a (text*).
It's the generic cast for indirect types.

> Using DatumGetPointer also seg faults ...

What actually segfault? Not DatumGetPointer() since that's just a cast.

> Is there somewhere that I am not adequately checking for an error?

Depends what you're doing. Remember, a (text*) is a varlena object so
you need to use the VAR_DATA,VAR_LEN macros to access it. The string is
not nul-terminated for example. If you want to get a plain C-string,
use textout or DatumToCString or something similar.

However, DETOAST is the right step, because if you don't do that you
might be handed a toasted string.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
> -- John F Kennedy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2007-12-04 15:51:23 Re: difficulty extracting variable-sized field on triggered row
Previous Message Pau Marc Munoz Torres 2007-12-04 15:41:18 Can i Force to postgrsql to use a certain index?