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

Non visible conflict on column definition and table constraints #201

Open
antoineB opened this issue Oct 12, 2023 · 0 comments
Open

Non visible conflict on column definition and table constraints #201

antoineB opened this issue Oct 12, 2023 · 0 comments

Comments

@antoineB
Copy link
Contributor

According to postgres and sqlite doc this sql is valid (key is a column name)

CREATE TABLE public.test (
    id bigint NOT NULL,
    key char(255) NOT NULL
);

But key is a keyword so the rule $._key_constraint is choosed instead of
$.column_definition.

I add to change the grammar.js to :

modified   grammar.js
@@ -12,6 +12,7 @@ module.exports = grammar({
     [$.object_reference, $._qualified_field],
     [$.object_reference],
     [$.between_expression, $.binary_expression],
+    [$._column, $._key_constraint],
   ],
 
   precedences: $ => [
@@ -1918,6 +1919,7 @@ module.exports = grammar({
 
     _column_list: $ => paren_list(alias($._column, $.column), true),
     _column: $ => choice(
+      $.keyword_key,
       $.identifier,
       alias($._literal_string, $.literal),
     ),

The conflict was mentioned at compile time when I added the $.keyword_key to
$._column.

In SQL many keyword are not reserved
(https://www.postgresql.org/docs/current/sql-keywords-appendix.html) and could
be used as identifier, should we add :

  _non_reserved_keyword: $ => choice(
      $.keyword_key,
      $.keyword_delete
      ...
      ),
  _identifier_keyword: $ => choice(
      $._identifier,
      $._non_reserved_keyword,
  ),

and replace $._identifier by $._identifier_keyword ?

Maybe there is a better solution with word ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant