Re: more custom C function fun

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Dan Heron Myers <heron(at)xnapid(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: more custom C function fun
Date: 2008-05-06 15:59:44
Message-ID: 20080506155944.GI19090@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 06, 2008 at 09:39:50AM -0600, Dan Heron Myers wrote:
> Using DatumToCString(mytextvariable), I get single-character-length
> strings that do not match the data actually in the fields.

Correct, because it's not a cstring. Pretending it is one gives you
garbage.

> Using VARDATA(mytextvariable) as the char*, I get things like this (name
> obscured) (using strlen to get the string's length):

Not null terminated.

> Which is what I need. Perhaps we could get some documentation about how
> to use this stuff? I was unable to find any on the Postgres site, if
> there is any.

Well, here's an example of how you should do it:

http://www.postgresql.org/docs/8.2/interactive/spi-examples.html

Not the most obvious place. The best place is the source,
utils/adt/text contains lots of functions on text variables, so you can
see how they work.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pau Marc Munoz Torres 2008-05-06 16:17:54 Re: select from an index
Previous Message Tom Lane 2008-05-06 15:56:42 Re: [GENERAL] psql \pset pager