X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id F35749FB3E1 for ; Sat, 9 Sep 2006 16:06:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 85685-01-5 for ; Sat, 9 Sep 2006 16:06:15 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.177]) by postgresql.org (Postfix) with ESMTP id 1086A9FB429 for ; Sat, 9 Sep 2006 14:26:11 -0300 (ADT) Received: by py-out-1112.google.com with SMTP id d80so1349852pyd for ; Sat, 09 Sep 2006 10:26:11 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=CWQ5dufN4AyCwA7Ke1Ddybp6gJ6dO1JMh8W1nb0DJxwVN4dDiH3fxAVrLt4dZSVDwuZrnetfdODyy+kgMuIvYTvtmfo1obLEYzEUkSpKluY9qZpCLNfqhuG+Cmxw8b59YhB6tLdr2yiycI/lYcf8DeUZuDLJSTRXgSO+dluqYS4= Received: by 10.35.93.19 with SMTP id v19mr5272018pyl; Sat, 09 Sep 2006 10:26:10 -0700 (PDT) Received: by 10.35.80.9 with HTTP; Sat, 9 Sep 2006 10:26:10 -0700 (PDT) Message-ID: Date: Sat, 9 Sep 2006 12:26:10 -0500 From: "Aaron Bono" To: emilu@encs.concordia.ca Subject: Re: Is it possible to left join based on previous joins result Cc: pgsql-sql@postgresql.org In-Reply-To: <45002689.9050307@encs.concordia.ca> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_54334_2386298.1157822770923" References: <45001AF6.4020706@encs.concordia.ca> <45002689.9050307@encs.concordia.ca> X-Google-Sender-Auth: c35f82d311085b37 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.643 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, HTML_30_40, HTML_MESSAGE, SPF_PASS X-Spam-Level: X-Archive-Number: 200609/55 X-Sequence-Number: 26266 ------=_Part_54334_2386298.1157822770923 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/7/06, Emi Lu wrote: > > I tried the example as the following: > > create table a(col1); > create table b(col1, col2) > > select a.* > from a inner join b using(col2) > left join b.col2 as c on (c.col1 = a.col1) > > System notifies me that b is not a schema name. > > So, I guess the approach that I tried to do is not acceptable by Pgsql > grammar. the syntax is LEFT JOIN [table] AS ... you have b.col2 which means the database will interpret col2 as the table name and subsequently b as the schema name You should have SELECT a.* FROM a INNER JOIN b using(col2) LEFT JOIN b as c on (c.col1 = a.col1) In the "using(col2)", what columns and tables are you joining there? I always dislike that syntax as it is ambiguous in some cases and not very easy to read. ================================================================== Aaron Bono Aranya Software Technologies, Inc. http://www.aranya.com http://codeelixir.com ================================================================== ------=_Part_54334_2386298.1157822770923 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 9/7/06, Emi Lu <emilu@encs.concordia.ca> wrote:
I tried the example as the following:

create table a(col1);
create table b(col1, col2)

select a.*
from a inner join b using(col2)
left join b.col2 as c on (c.col1 = a.col1)

System notifies me that b is not a schema name.

So, I guess the approach that I tried to do is not acceptable by Pgsql
grammar.

 
the syntax is
LEFT JOIN [table] AS ...

you have b.col2 which means the database will interpret col2 as the table name and subsequently b as the schema name

You should have
SELECT a.*
FROM a
INNER JOIN b using(col2)
LEFT JOIN b as c on (c.col1 = a.col1)

In the "using(col2)", what columns and tables are you joining there?  I always dislike that syntax as it is ambiguous in some cases and not very easy to read.

==================================================================
   Aaron Bono
   Aranya Software Technologies, Inc.
   http://www.aranya.com
   http://codeelixir.com
================================================================== ------=_Part_54334_2386298.1157822770923--