[
https://issues.apache.org/jira/browse/DERBY-4369?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Knut Anders Hatlen updated DERBY-4369:
--------------------------------------
Attachment: derby-4369-1a.diff
Here's a patch that makes the ON clause optional in the grammar, which makes it
possible that the parser sees onClause==null and emits the error message for it.
The patch also updates the canons for lang/innerjoin.sql, lang/outerjoin.sql
and lang/db2Compatibility.sql, which now see a different error message/SQLState
when the join lacks an ON clause. Both derbyall and suites.All run cleanly with
the patch.
All the changed errors go from SQLState 42X01 to SQLState 42Y11. Most of the
old error messages are on the form "Syntax error: Encountered "<EOF>" at line
3, column 30."
Some special cases to notice:
1) If you use a USING clause instead of an ON clause, the old message would say
something along these lines:
ERROR 42X01: Syntax error: Encountered "USING" at line 2, column 37.
Whereas the new message says:
ERROR 42Y11: A join specification is required with the 'LEFT OUTER JOIN' clause.
Since a USING clause is a join specification, the new message is not entirely
clear in this case. Perhaps it should rather have used the term "ON clause"
instead of join specification. Or we could just implement the USING clause
(DERBY-4370) to avoid the problem altogether.
2) For a query such as "SELECT * FROM t1 CROSS JOIN t2", we would previously
get the EOF message, but now we'll get this instead:
ERROR 42Y11: A join specification is required with the 'INNER JOIN' clause.
This may look a bit odd, since the query is apparently a CROSS JOIN and not an
INNER JOIN. The explanation is that CROSS JOIN is not implemented yet
(DERBY-4355) and CROSS is not a reserved keyword in Derby's parser. Because of
this, CROSS is interpreted as an identifier which acts as an alias for T1.
Derby therefore treats this as an INNER JOIN and not a CROSS JOIN, as would
become apparent if an ON clause was added, and the error message is correct.
> Give a more useful error message when join specification is missing
> -------------------------------------------------------------------
>
> Key: DERBY-4369
> URL: https://issues.apache.org/jira/browse/DERBY-4369
> Project: Derby
> Issue Type: Improvement
> Components: SQL
> Affects Versions: 10.6.0.0
> Reporter: Knut Anders Hatlen
> Assignee: Knut Anders Hatlen
> Priority: Minor
> Attachments: derby-4369-1a.diff
>
>
> Currently, if a join is missing a join specification, we see the following
> rather cryptic message:
> ij> select * from t1 join t2;
> ERROR 42X01: Syntax error: Encountered "<EOF>" at line 1, column 24.
> Issue the 'help' command for general information on IJ command syntax.
> Any unrecognized commands are treated as potential SQL commands and executed
> directly.
> Consult your DBMS server reference documentation for details of the SQL
> syntax supported by your server.
> The parser already has code to check if the join specification is missing,
> but since the join specification is required in the grammar, we'll never get
> to that point in the code if it is missing. If we make the join specification
> optional in the grammar, the code path with the more helpful message will be
> enabled, and we'll see this instead:
> ij> select * from t1 join t2;
> ERROR 42Y11: A join specification is required with the 'INNER JOIN' clause.
> This will make it clearer what the problem is.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.