Re: [HACKERS] Curiously confused query parser. - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Curiously confused query parser.
Date
Msg-id 2550.943025762@sss.pgh.pa.us
Whole thread Raw
In response to Curiously confused query parser.  ("Gene Sokolov" <hook@aktrad.ru>)
List pgsql-hackers
"Gene Sokolov" <hook@aktrad.ru> writes:
> This query is fine:

> test=> select o1.id from ord as o1, ord as o2 where o1.pos>2 and o2.pos<2
test-> and o1.tp=o2.tp;
> id
> --
>  5
>  3
> (2 rows)

> And this one is invalid:

> test=> select o1.id from ord as o1, ord as o2 where o1.pos>2 and o2.pos<2
test-> and o1.tp=o2.tp and ord.id>3;
> id
> --
>  5
>  5
>  3
>  3
> (4 rows)

It's not invalid, at least not according to Postgres' view of the world;
your reference to ord.id adds an implicit "FROM ord AS ord" to the FROM
clause, turning the query into a 3-way join.  The output is correct for
that interpretation.

Implicit FROM clauses are a POSTQUEL leftover that is not to be found
in the SQL92 spec.  There's been some talk of emitting a warning message
when one is added, because we do regularly see questions from confused
users.  But if we took the feature out entirely, we'd doubtless break
some existing applications :-(
        regards, tom lane


pgsql-hackers by date:

Previous
From: Thomas Lockhart
Date:
Subject: Re: [HACKERS] Primary key requires SERIAL
Next
From: Thomas Lockhart
Date:
Subject: Mandrake Postgres RPMs