gwenn / lemon-rs

LALR(1) parser generator for Rust based on Lemon + SQL parser
The Unlicense
48 stars 10 forks source link

support strange joins #24

Open MarinPostma opened 1 year ago

MarinPostma commented 1 year ago

Sqite has a rather flexible syntax for joins, and the parser should support them. This PR alleviate the restriction on joins, and make them more flexible.

see: https://www.sqlite.org/lang_select.html#strange_join_names

psarna commented 1 year ago

@MarinPostma https://github.com/gwenn/lemon-rs/issues/23#issuecomment-1458636586 it looks like weird joins are fine on their own, looks like we hit another kind of issue

MarinPostma commented 1 year ago

No they aren't, for example, this is not supported by the parser, but should: SELECT * FROM foo LEFT NATURAL JOIN bar

gwenn commented 1 year ago

I am going to try fixing #23 first. https://www.sqlite.org/lang_select.html#strange_join_names

Remember: you can use these non-standard join types but you ought not. Stick to using standard JOIN syntax for portability with other SQL database engines.

And I am not sure we want to support these non-standard join types (like Double-Quoted String).

gwenn commented 1 year ago

It seems that the actual rules are here: https://github.com/sqlite/sqlite/blob/80511f32f7e71062026edd471913ef0455563964/src/select.c#L197-L257

The only restrictions on the join type name are:

  • "INNER" cannot appear together with "OUTER", "LEFT", "RIGHT", or "FULL".

  • "CROSS" cannot appear together with "OUTER", "LEFT", "RIGHT, or "FULL".

  • If "OUTER" is present then there must also be one of "LEFT", "RIGHT", or "FULL"

MarinPostma commented 1 year ago

I'll implement that 👍

gwenn commented 9 months ago

See #37