Re: count() and multiple tables - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: count() and multiple tables
Date
Msg-id Pine.BSF.4.21.0103191720420.27292-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: count() and multiple tables  (Joseph Shraibman <jks@selectacast.net>)
Responses Re: count() and multiple tables  ("Josh Berkus" <josh@agliodbs.com>)
List pgsql-sql
> > And postgres tries to be helpful again... :(  [I *really* dislike this
> > adding to from list thing]  Technically the above should be illegal
> > because no from list contains u or a.  Postgres is adding them to the
> > from list for you.
> > 
> I get the same result if I do:
> select count(d.id) from d where status = 2 and d.id = u.dkey and
> u.status = 2 and not u.b and u.akey = a.key and a.status = 3;
> 
> So in standard SQL all the tables you join accross are required to be in
> the FROM?

Basically, yes.  It's more complicated than that probably (what isn't in
SQL), but that's the general idea.

Postgres assumes your query is
select count(*) from d,u,a ...

Because d.id was guaranteed to be unique, you might be able to 
count(distinct d.id) and get the result you want. [I think the 
subquery is a nicer way of representing it]




pgsql-sql by date:

Previous
From: Tim Pizey
Date:
Subject: Re: Invalid (null) int8, can't convert to float8
Next
From: Joseph Shraibman
Date:
Subject: Re: VACUUM kills Index Scans ?!