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

Composite primary key, key & index in CREATE TABLE #260

Open
hubg398 opened this issue May 27, 2024 · 1 comment
Open

Composite primary key, key & index in CREATE TABLE #260

hubg398 opened this issue May 27, 2024 · 1 comment

Comments

@hubg398
Copy link

hubg398 commented May 27, 2024

Found another one while testing out the lib, logging it here to keep track for now.

Issue is with parsing composite primary keys with multiple columns

            CREATE TABLE `TABLE_2` (
                `column_1` int(11),
                `column_2` int(11),
                `column_3` int(11),
                `column_4` int(11),
                `column_5` int(11),
                `column_6` int(11),
                `column_7` int(11),
                `column_8` int(11),
                PRIMARY KEY `indexColumn1Column2` (`column_1`, `column_2`), /* This doesnt show in output */
                PRIMARY KEY `indexColumn1Column3Column8` (`column_1`, `column_3`, `column_8`),
                /* This doesnt show in output */
                PRIMARY KEY `indexColumn5` (`column_5`), /* This shows correctly in tables['primary_key'] */
            );
@hubg398
Copy link
Author

hubg398 commented May 27, 2024

I think related to this, same issue parsing KEY/INDEX of the same syntax

CREATE TABLE `TABLE_2` (
                `column_1` int(11),
                `column_2` int(11),
                `column_3` int(11),
                `column_5` int(11),
                `column_8` int(11),
                KEY `indexColumn1Column2` (`column_1`, `column_2`), /* Doesnt crash, but incorrect. Only shows `column_1` as the column of the index
                KEY `indexColumn1Column3Column8` (`column_1`, `column_3`, `column_8`), /* Crashes when there's more than 2 columns here. Table fails to parse.
                KEY `indexColumn5` (`column_5`), /* Parses correctly */
            );

And also the UNIQUE variants

            CREATE TABLE `TABLE_2` (
                `column_1` int(11),
                `column_2` int(11),
                `column_3` int(11),
                `column_5` int(11),
                `column_8` int(11),
                UNIQUE `indexColumn1Column2` (`column_1`, `column_2`), /* Fails, lex error */
                UNIQUE `indexColumn1Column3Column8` (`column_1`, `column_3`, `column_8`), /* Fails, lex error */
                UNIQUE `indexColumn5` (`column_5`), /* Fails, lex error */
            );

Interestingly, it works if we swap 'UNIQUE' -> 'UNIQUE KEY'

@hubg398 hubg398 changed the title Composite primary key in CREATE TABLE Composite primary key, key & index in CREATE TABLE May 31, 2024
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