Re: more custom C function fun

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

Martijn van Oosterhout wrote:
> You do realise that VARDATA does not return a null terminated string?

I did not realize that... but it led me in the right direction.

> Try using something like text_to_cstring or using elog(NOTICE) to
> display what's actually being compared.

I've outputted some things with elog (which is the other thing I needed
to figure this out).

Using DatumToCString(mytextvariable), I get single-character-length
strings that do not match the data actually in the fields.

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

string: "Hillary Clinton(6611)", length 21
string: "95555551234nton(6611)", length 21

Of course, then I realized that strlen isn't the right tool for the job;
I need: int len = VARSIZE(mytextvariable) - VARHDRSZ;

Using that with the VARDATA as my char*, I get this:

string: "Hillary Clinton(6611)" - length: 21
string: "95555551234" - length: 11

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.

Thanks for your help guys :)

- Dan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2008-05-06 15:56:42 Re: [GENERAL] psql \pset pager
Previous Message Bruce Momjian 2008-05-06 15:37:57 Re: [GENERAL] psql \pset pager