X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 85CB7D1B20D for ; Mon, 21 Jun 2004 11:19:44 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33533-02 for ; Mon, 21 Jun 2004 14:19:45 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id BC5EAD1B187 for ; Mon, 21 Jun 2004 11:19:39 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i5LEJhTc001917; Mon, 21 Jun 2004 10:19:44 -0400 (EDT) To: Gary Stainburn Cc: pgsql-sql@postgresql.org Subject: Re: subselect prob in view In-reply-to: <200406211110.39940.gary.stainburn@ringways.co.uk> References: <200406211110.39940.gary.stainburn@ringways.co.uk> Comments: In-reply-to Gary Stainburn message dated "Mon, 21 Jun 2004 11:10:39 +0100" Date: Mon, 21 Jun 2004 10:19:43 -0400 Message-ID: <1916.1087827583@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/195 X-Sequence-Number: 18140 Gary Stainburn writes: > from requests r, users u, request_types t, > request_states s, dealerships d, departments de, customers c > left outer join (select co_r_id, count(co_r_id) from comments group > by co_r_id) co on > co.co_r_id = r.r_id > psql:goole1.sql:45: ERROR: Relation "r" does not exist I think you have learned some bad habits from MySQL :-( PostgreSQL follows the SQL spec and makes JOIN bind more tightly than comma. Therefore, in the above the LEFT JOIN is only joining "c" to "co" and its JOIN ON clause can only reference those two relations. You could get the behavior you seem to expect by changing each comma in the from-list to CROSS JOIN. Then the JOINs all bind left-to-right and so "r" will be part of the left argument of the LEFT JOIN. Note that if you are using a pre-7.4 release this could have negative effects on performance --- see the user's guide concerning how explicit JOIN syntax constrains the planner. regards, tom lane