Re: BUG #5506: Error in the grammar of de joins

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Fernando Cano" <fcano(at)uniovi(dot)es>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5506: Error in the grammar of de joins
Date: 2010-06-14 14:20:24
Message-ID: 12428.1276525224@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Fernando Cano" <fcano(at)uniovi(dot)es> writes:
> This sentences are valid with your grammar but generate an error.

> create table t1 ( id_t1 smallint, name text);
> create table t2 ( id_t2 smallint, name text);

> select * from natural join using (id) ;
> select * from t1 natural cross join t2;
> select * from natural cross join using (id) ;
> select * from t1 join t2;
> select t1 natural left join t2;

Uh, no, they're *not* valid with our grammar --- that's why you're
getting errors. They're not valid according to the SQL standard
either, so I'm not sure exactly what your point is.

> I have problems when I explain to my students the sintax of the joins.

The SQL92 standard defines join syntax like this:

<joined table> ::=
<cross join>
| <qualified join>
| <left paren> <joined table> <right paren>

<cross join> ::=
<table reference> CROSS JOIN <table reference>

<qualified join> ::=
<table reference> [ NATURAL ] [ <join type> ] JOIN
<table reference> [ <join specification> ]

<join specification> ::=
<join condition>
| <named columns join>

<join condition> ::= ON <search condition>

<named columns join> ::=
USING <left paren> <join column list> <right paren>

<join type> ::=
INNER
| <outer join type> [ OUTER ]
| UNION

<outer join type> ::=
LEFT
| RIGHT
| FULL

<join column list> ::= <column name list>

The restriction that NATURAL can't appear with ON or USING isn't
in this syntax diagram, though; it's explained in the text.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2010-06-14 15:06:21 Re: BUG #5507: missing chunk number 0 for toast value XXXXX in pg_toast_XXXXX
Previous Message Tom Lane 2010-06-14 14:13:41 Re: BUG #5505: Busted referential integrity with triggers