I have a custom C function that takes two text*s and returns a text*.
My problem is with this code:
PG_FUNCTION_INFO_V1(get_agent);
PGMODULEEXPORT Datum get_agent(PG_FUNCTION_ARGS)
{
if(!PG_ARGISNULL(0))
{
text* calling_party = PG_GETARG_TEXT_P(0);
char* thestr = VARDATA(calling_party);
if(thestr[20] == ')')
{
PG_RETURN_TEXT_P(calling_party);
}
}
/* the other argument is ignored for now */
PG_RETURN_NULL();
}
The problem is, the comparison in the inner if statement is always true.
If I change to compare, say, thestr[0] == 'N', then it works as
expected (returning only those text*s whose first letter is N, returning
null for the rest).
However if I try to compare any character inside the text* with a
parenthesis (both '(' and ')'), then the equality is apparently always
true (the function never returns null, always returning calling_party),
whether or not there is any data in that column that contains a
parenthesis in that column.
Does anyone know of any oddities or whatnot I should be accounting for
when reading character data out of a text*?
- Dan