Re: Question about Encoding a Custom Type - Mailing list pgsql-hackers

From David E. Wheeler
Subject Re: Question about Encoding a Custom Type
Date
Msg-id 6EF5F3C6-22D2-43C1-AAD2-5AD9B8E5AE59@kineticode.com
Whole thread Raw
In response to Re: Question about Encoding a Custom Type  (Martijn van Oosterhout <kleptog@svana.org>)
Responses Re: Question about Encoding a Custom Type  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Jun 16, 2008, at 13:41, Martijn van Oosterhout wrote:

> Actually, real dumb question but: arn't you assume that text* values
> are NULL terminated, because they're not...
>>
>> char * cilower(text * arg) {
>>    // Do I need to free anything here?
>>    char * str = VARDATA_ANY( arg );
>
> str here is not null terminated. You need text_to_cstring or something
> similar.

Ah! That makes sense. I changed it to this:

#define GET_TEXT_STR(textp) DatumGetCString( \    DirectFunctionCall1( textout, PointerGetDatum( textp ) ) \
)

char * cilower(text * arg) {    // Do I need to free anything here?    char * str  = GET_TEXT_STR( arg );
...

And now I don't get that error anymore. W00t! Many thanks.

Now I have just one more bizarre error: PostgreSQL thinks that a
citext column is not in an aggregate even when it is:

try=# CREATE AGGREGATE array_accum (anyelement) (
try(#     sfunc = array_append,
try(#     stype = anyarray,
try(#     initcond = '{}'
try(# );
try=# CREATE TEMP TABLE srt ( name CITEXT );
try=#
try=# INSERT INTO srt (name)
try-# VALUES ('aardvark'),
try-#        ('AAA'),
try-#        ('â');
try=# select array_accum(name) from srt order by name;
ERROR:  column "srt.name" must appear in the GROUP BY clause or be
used in an aggregate function

Um, what? Again, I'm sure I'm just missing something really stupid.
What might cause this?

Many thanks all,

David

pgsql-hackers by date:

Previous
From: Josh Berkus
Date:
Subject: Re: pg_stat_statements
Next
From: Tom Lane
Date:
Subject: Reducing overhead for repeat de-TOASTing