pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: kunert@cms.hu-berlin.de
To: pgsql-bugs@postgresql.org
Subject: BUG #12000: "CROSS JOIN" not equivalent to ","
Date: Tue, 18 Nov 2014 17:11:26 +0000
Message-ID: <20141118171126.2479.55006@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      12000
Logged by:          Andreas Kunert
Email address:      kunert@cms.hu-berlin.de
PostgreSQL version: 9.3.5
Operating system:   Ubuntu 14.04.1 LTS
Description:        

Still not sure if this is really a bug, but I could not find a good
explanation for the following behaviour:

According to the documentation
http://www.postgresql.org/docs/9.3/static/queries-table-expressions.html
(7.2.1.1):
"FROM T1 CROSS JOIN T2 is equivalent to FROM T1, T2"

However, in the following example the SQL-Query using "CROSS JOIN" works,
while the usage of "," results in an invalid reference:



drop table if exists table1;
drop table if exists table2;

create table table1 (x integer);
create table table2 (y integer, z integer);

insert into table1 (x) values (1), (2);
insert into table2 (y,z) values (1,1), (1,2);

-- this query works:

select
	a.x, b.x, c.y
	
from
	table1 a
	cross join table1 b
	left outer join table2 c on a.x = y and b.x = z;

-- this does not:

select
	a.x, b.x, c.y
	
from
	table1 a
	, table1 b
	left outer join table2 c on a.x = y and b.x = z;




The error in the latter case is:

ERROR:  invalid reference to FROM-clause entry for table "a"
LINE 29:  left outer join table2 c on a.x = y and b.x = z;
                                      ^
HINT:  There is an entry for table "a", but it cannot be referenced from
this part of the query.

********** Error **********

ERROR: invalid reference to FROM-clause entry for table "a"
SQL state: 42P01
Hint: There is an entry for table "a", but it cannot be referenced from this
part of the query.
Character: 447




Another example resulting in the same error but without using table
aliases:


drop table if exists table0;
drop table if exists table1;
drop table if exists table2;

create table table0 (x integer);
create table table1 (x integer);
create table table2 (y integer, z integer);

insert into table0 (x) values (1), (2);
insert into table1 (x) values (1), (2);
insert into table2 (y,z) values (1,1), (1,2);

-- works:

select
	table0.x, table1.x, table2.y
	
from
	table0 
	cross join table1 
	left outer join table2 on table0.x = y and table1.x = z;

-- does not work:

select
	table0.x, table1.x, table2.y
	
from
	table0 
	, table1 
	left outer join table2 on table0.x = y and table1.x = z;




-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (12+ messages)  latest in thread

Message-ID: <20141118171126.2479.55006@wrigleys.postgresql.org>
Permalink:  ../20141118171126.2479.55006@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20141118171126.2479.55006@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kunert@cms.hu-berlin.de
  Subject: Re: BUG #12000: "CROSS JOIN" not equivalent to ","
  In-Reply-To: <20141118171126.2479.55006@wrigleys.postgresql.org>
  References: <20141118171126.2479.55006@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox