join ... using ... and - is this expected behaviour?

From: Rob Johnston <rob(at)jenisys(dot)com(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: join ... using ... and - is this expected behaviour?
Date: 2008-06-03 06:49:29
Message-ID: 4844E979.7020808@jenisys.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Just wondering if this is expected behaviour. When executing a query in
the form of:

select column from table join table using (column) and column = clause

pgsql (8.2) returns the following: syntax error at or near "and"

Obviously, you can get around this by using "where" instead of "and",
but shouldn't the format as used above be valid? The following is...

select column from table join table on (column = column) and column = clause

The documentation indicates that the two formats of the query are
equivalent
(http://www.postgresql.org/docs/8.2/interactive/queries-table-expressions.html#QUERIES-JOIN)

The following test case illustrates the issue:

CREATE TABLE table1
(
columnone integer,
columntwo integer
);

CREATE TABLE table2
(
columntwo integer,
columnthree integer
);

insert into table1 values (1, 1), (2, 1);

insert into table2 values (1, 3);

This query results in a syntax error:

select t1.columnone, t1.columntwo, t2.columnthree
from table1 t1 join table2 t2
using (columntwo) and columnone = 1

This query executes as expected:

select t1.columnone, t1.columntwo, t2.columnthree
from table1 t1 join table2 t2
on (t1.columntwo = t2.columntwo) and columnone = 1

Rob Johnston

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2008-06-03 07:26:52 Re: turning fsync off for WAL
Previous Message Hiroshi Saito 2008-06-03 04:16:35 Re: FW: make rows unique across db's without UUIP on windows?