Re: Counting records in a child table

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Mike Orr'" <sluggoster(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: Counting records in a child table
Date: 2011-04-01 01:57:21
Message-ID: 00c601cbf010$247c4ce0$6d74e6a0$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Not fully sure on the syntax of the Window to accomplish the specified goal
- and am not sure it would be any cleaner anyway.

But, the reason I am responding is how you phrased "...windows only compared
groups of records in the same table".

When I say:

FROM tableA
* JOIN tableB

I have now effectively created a new "table" in the sense that anything I
can do on tableA or tableB I can also do on the result of the joining of
those two tables.

Re-reading the comment and context it probably would be more fair to guess
that you know this. In the context of a Window function you can use it
AFTER you perform a LEFT JOIN - but you may not need to do the "SELECT id,
count(*) GROUP BY id" on the child table but instead can just do a direct
left join onto child and use a Window.

Again, mostly just speculation and for the moment I don't have the time to
spare to try out a Window based solution; especially since my gut says the
LEFT JOIN on the grouped child is likely the best solution anyway.

David J.

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Mike Orr
Sent: Thursday, March 31, 2011 3:20 PM
To: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] Counting records in a child table

Thanks. How would I do it with a window function? I thought windows only
compared groups of records in the same table.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Marco Colombo 2011-04-01 02:00:35 Re: pg_restore
Previous Message Marco Colombo 2011-04-01 01:44:07 Re: Pl/Python error when import "from __future__"