Re: Question about Encoding a Custom Type

From: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
To: Martijn van Oosterhout <kleptog(at)svana(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Question about Encoding a Custom Type
Date: 2008-06-16 19:10:22
Message-ID: 6EF5F3C6-22D2-43C1-AAD2-5AD9B8E5AE59@kineticode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-06-16 19:35:26 Reducing overhead for repeat de-TOASTing
Previous Message Josh Berkus 2008-06-16 19:07:40 Re: pg_stat_statements