Re: question about count(b) where b is a custom type - Mailing list pgsql-hackers

From Martijn van Oosterhout
Subject Re: question about count(b) where b is a custom type
Date
Msg-id 20051116123012.GF31063@svana.org
Whole thread Raw
In response to question about count(b) where b is a custom type  (Grzegorz Jaskiewicz <gj@pointblue.com.pl>)
List pgsql-hackers
On Wed, Nov 16, 2005 at 10:05:36AM +0100, Grzegorz Jaskiewicz wrote:
> Hi folks
>
> We're developing here gist index (which works finally, and I remember
> about writing some docs about it).
> I have few fprintf(stderr,""") in function that converts internal
> rep. into string. I was really supprised to see them on me screen when :
> select count(b) from blah where b ~ 'something';
> was issued. What the hell, isn't it wrong ? I don't need strings to
> count results, right ?
> IMO this is a serious bug.
> What do yah think ?

Firstly, if you just want a count, what's wrong with count(1) or
count(*).

Secondly, if you want an aggregate to work on your new type, you should
declare it as such. This is one of the reasons why implicit casts to
text are discouraged. If it had to be explicit, the parser would have
told you that what you asked for wasn't possible directly. (There's no
count(yourtype) function defined).

See CREATE AGGREGATE.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Reproducable deadlock situation (possibly with foreign keys)
Next
From: Hannu Krosing
Date:
Subject: Re: question about count(b) where b is a custom type