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

Duplicate column in CREATE TABLE statement #668

Open
gwenn opened this issue Oct 12, 2022 · 2 comments
Open

Duplicate column in CREATE TABLE statement #668

gwenn opened this issue Oct 12, 2022 · 2 comments

Comments

@gwenn
Copy link

gwenn commented Oct 12, 2022

SQLite raises a parser error with the following DDL:

sqlite> CREATE TABLE test (
   ...> x TEXT,
   ...> x TEXT
   ...> );
Parse error: duplicate column name: x

But sqlparser doesn't:

% cargo run --example cli ddl.sql --sqlite
...
Round-trip:
'CREATE TABLE test (x TEXT, x TEXT)'
Parse results:
[
    CreateTable {
...

Is this kind of checks considered out of scope ?
Thanks.

@AugustoFKL
Copy link
Contributor

AugustoFKL commented Oct 14, 2022

@gwenn I think this is something really specific, and validating semantics is a really dangerous place to go.

I think we could look into that, but that would require a good study of the approach of each dialect and, as stated on SQL ANSI 2011 (1):

Sometimes the Syntax Rules forbid two elements at different ordinal positions from having
equivalent names (particularly when created through an ). When two elements with
equivalent names are permitted, then the element name is ambiguous and attempts to reference either element
by name will raise a syntax error.

Therefore, not necessarily all databases return errors when we have ambiguous columns on creation. @alamb what do you think?

@alamb
Copy link
Contributor

alamb commented Oct 18, 2022

I agree -- this crate is designed to parse SQL syntax and does so quite forgivingly (doesn't error as much as parsers tied to a specific implementation might).

We have purposely left checks of what syntax is semantically valid / invalid to the users of this crate.

Another example is that I suspect this crate parses more and different data types than sqlite allows

@AugustoFKL maybe this is good information we can add to the readme so it doesn't keep getting asked or causing confusion

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

3 participants