The specific problem I'm trying to solve involves a user table with
some history.
Something like this:
create table user_history (
user_id int
event_time_stamp timestamp
);
I'd like to be able to count the distinct user_ids in this table, even
if it were joined to other tables.
On Tue, 16 Nov 2004, Thomas F.O'Connell wrote:
> Hmm. I was more interested in using COUNT( * ) than DISTINCT *.
>
> I want a count of all rows, but I want to be able to specify which
> columns are distinct.
I'm now a bit confused about exactly what you're looking for in the end.
Can you give a s
Hmm. I was more interested in using COUNT( * ) than DISTINCT *.
I want a count of all rows, but I want to be able to specify which
columns are distinct.
That's definitely an interesting approach, but testing doesn't show it
to be appreciably faster.
If I do a DISTINCT *, postgres will attempt t
On Tue, 16 Nov 2004, Thomas F.O'Connell wrote:
> Is there another way to accomplish what the former is doing, then?
The only thing I can think of is a subselect in from that uses distinct.
select count(*) from (select distinct ...) foo
That also theoretically allows you to use select distinct *
Is there another way to accomplish what the former is doing, then?
For practical reasons, I'd like to come up with something better.
For theoretical curiosity, I'd like to know whether there's a way to
combine COUNT and DISTINCT that still allows one to reference * rather
than naming specific col
On Tue, 16 Nov 2004, Thomas F.O'Connell wrote:
> I am wondering whether the following two forms of SELECT statements are
> logically equivalent:
>
> SELECT COUNT( DISTINCT table.column ) ...
>
> and
>
> SELECT DISTINCT COUNT( * ) ...
Not in general.
The former counts how many distinct table.colu
I am wondering whether the following two forms of SELECT statements are
logically equivalent:
SELECT COUNT( DISTINCT table.column ) ...
and
SELECT DISTINCT COUNT( * ) ...
If they are the same, then why is the latter query much slower in
postgres when applied to the same FROM and WHERE clauses?