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

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Rob Johnston <rob(at)jenisys(dot)com(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: join ... using ... and - is this expected behaviour?
Date: 2008-06-03 14:39:59
Message-ID: 20080603073043.T32843@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 3 Jun 2008, Rob Johnston wrote:

> 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?

No.

> The following is...
>
> select column from table join table on (column = column) and column = clause

Yes.

USING takes a column list, ON takes an expression as a search condition
(and note from the syntax section that the parens are not always required
around the expression). "(t1.col1 = t2.col1) AND col3 = foo" is still a
valid search condition, but "(col1) AND col3 = foo" isn't a valid column
list.

> 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)

It's talking about the execution, not the syntax, but that could probably
be more clear.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mason Hale 2008-06-03 14:43:25 bloom filter indexes?
Previous Message Scott Marlowe 2008-06-03 14:06:59 Re: Database growing. Need autovacuum help.