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

fix(sqlite): Fix UNIQUE parsing #4293

Merged
merged 2 commits into from
Oct 25, 2024
Merged

fix(sqlite): Fix UNIQUE parsing #4293

merged 2 commits into from
Oct 25, 2024

Conversation

VaggelisD
Copy link
Collaborator

@VaggelisD VaggelisD commented Oct 25, 2024

Fixes #4291

The following issues appear throughout these cases are the following:

  1. UNIQUE can be used as a standalone column constraint:
CREATE TABLE foo (bar TEXT UNIQUE REFERENCES "baz")

However, parser.py::_parse_unique() can end up consuming the following constraints, so this PR overrides it to add the appropriate lookahead.

  1. Implicit aliases can be used in column definitions, e.g:
CREATE TABLE foo (bar baz TEXT) -> fine
CREATE TABLE foo (bar AS baz TEXT) -> error

Which is solved by overriding parser.py::_parse_field_def() to also parse the alias & generating it back without the AS prefix.

@VaggelisD
Copy link
Collaborator Author

VaggelisD commented Oct 25, 2024

It's actually not clear what's the behavior leading to the 2nd issue; If it was an alias, the AS version wouldn't lead to an error and it would be possible to select it directly. Here are some interesting examples of that:

  • It's valid to include multiple identifiers before the type
sqlite> create table test (foo bar baz TEXT); 
sqlite> insert into test values (1);
sqlite> select * from test;
1
sqlite> select foo from test;
1
  • Upon inspecting the table definition, the 2nd+ identifier(s) leak into the type (?)
sqlite> PRAGMA table_info("test");
0|foo|bar baz TEXT|0||0

For these reasons, I'll revert the solution to (2)

@VaggelisD VaggelisD changed the title fix(sqlite): Fix UNIQUE and ColumnDef alias parsing fix(sqlite): Fix UNIQUE parsing Oct 25, 2024
@georgesittas georgesittas merged commit 47bc09a into main Oct 25, 2024
6 checks passed
@georgesittas georgesittas deleted the vaggelisd/sqlite_ddl branch October 25, 2024 12:18
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

Successfully merging this pull request may close these issues.

Parser doesn't recognize a foreign-key-clause within a column definition after unique for sqlite
2 participants