Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional clauses/keywords to the insert statement #118

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 41 additions & 9 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ module.exports = grammar({
keyword_preserve: _ => make_keyword("preserve"),
keyword_unsigned: _ => make_keyword("unsigned"),
keyword_zerofill: _ => make_keyword("zerofill"),
keyword_conflict: _ => make_keyword("conflict"),
keyword_do: _ => make_keyword("do"),
keyword_nothing: _ => make_keyword("nothing"),
keyword_high_priority: _ => make_keyword("high_priority"),
keyword_low_priority: _ => make_keyword("low_priority"),
keyword_delayed: _ => make_keyword("delayed"),

// Hive Keywords
keyword_external: _ => make_keyword("external"),
Expand Down Expand Up @@ -948,18 +954,46 @@ module.exports = grammar({
),

insert: $ => seq(
choice($.keyword_insert, $.keyword_replace),
$.keyword_into,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is keyword_into now optional? For which dialect is this change?.

Copy link
Contributor Author

@wishdev wishdev Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL does not require it - I thought it was always optional but apparently not. [1] is the MySQL reference

SQL Server does not require it either it appears [2]

[1] - https://dev.mysql.com/doc/refman/8.0/en/insert.html
[2] - https://learn.microsoft.com/en-us/sql/t-sql/statements/insert-transact-sql?view=sql-server-ver16

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes. Before your PR the grammar required an INTO keyword, but it looks like it is optional in MySQL and MariaDB as well.

choice(
$.keyword_insert,
$.keyword_replace
),
optional(
choice(
$.keyword_low_priority,
$.keyword_delayed,
$.keyword_high_priority,
),
),
optional($.keyword_ignore),
optional($.keyword_into),
$.table_reference,
optional(
seq(
$.keyword_as,
field('table_alias', $._alias_identifier)
)
),
),
choice(
$._insert_values,
$._insert_set,
$._set_values,
),
optional(
seq(
$.keyword_on,
$.keyword_conflict,
seq(
$.keyword_do,
choice(
$.keyword_nothing,
seq(
$.keyword_update,
$._set_values,
optional($.where),
),
),
),
),
),
),

Expand All @@ -974,7 +1008,7 @@ module.exports = grammar({
),
),

_insert_set: $ => seq(
_set_values: $ => seq(
$.keyword_set,
comma_list($.assignment, true),
),
Expand All @@ -1000,17 +1034,15 @@ module.exports = grammar({
seq(
comma_list($.relation, true),
repeat($.join),
$.keyword_set,
comma_list($.assignment, true),
$._set_values,
optional($.where),
),
),

_postgres_update_statement: $ => prec(1,
seq(
$.relation,
$.keyword_set,
comma_list($.assignment, true),
$._set_values,
optional($.from),
),
),
Expand Down
195 changes: 139 additions & 56 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading