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

Parsing of INDEX or UNIQUE KEY within CREATE TABLE statements #253

Closed
hubg398 opened this issue May 15, 2024 · 7 comments
Closed

Parsing of INDEX or UNIQUE KEY within CREATE TABLE statements #253

hubg398 opened this issue May 15, 2024 · 7 comments
Assignees

Comments

@hubg398
Copy link

hubg398 commented May 15, 2024

Is your feature request related to a problem? Please describe.
It fails parsing INDEX and UNIQUE KEY of columns, within CREATE TABLE .... statements. Which should be valid, at least for MySQL

Sample SQL:

CREATE TABLE `posts`(
    `integer_column__unique` INT NOT NULL AUTO_INCREMENT UNIQUE,   
    `integer_column__unique_key` INT NOT NULL AUTO_INCREMENT UNIQUE KEY,               
    `integer_column__index` INT NOT NULL AUTO_INCREMENT INDEX
);
  • 'integer_column__unique' with UNIQUE - ✅ This parses
  • 'integer_column__unique_key' with UNIQUE KEY - ❌ This parses, but doesnt identify the column as unique. It incorrectly identifies the column as primary key instead
  • 'integer_column__index' with INDEX - ❌ This fails to parses, gives no output (empty list)

Thanks btw for the work on this parser, works a charm in a lot of cases.

@xnuinside
Copy link
Owner

@hubg398, thanks for opening the issue! I will try to take a look on it this week

@xnuinside xnuinside self-assigned this May 17, 2024
@xnuinside
Copy link
Owner

xnuinside commented May 18, 2024

@hubg398 I fixed case integer_column__unique_key INT NOT NULL AUTO_INCREMENT UNIQUE KEY, , but I cannot find docs for DB where AUTO_INCREMENT can be used with INDEX, can you give some info about that is this DB and link for the doc with that statement? I will really appreciate

@xnuinside
Copy link
Owner

I fixed the first case in PR #256 and released version 1.5.0

@hubg398
Copy link
Author

hubg398 commented May 19, 2024

Wow quick, thanks. Giving it a go.

Yea you're right it doesn't make sense to have AUTO_INCREMENT with INDEX, I think MySQL parses it without applying the AUTO_INCREMENT.

Either way, without the AUTO_INCREMENT

DDLParser("""CREATE TABLE `posts`(            
    `integer_column__index` INT NOT NULL INDEX
);""").run()

print(parse_results)

also returns [], which is probably not expected?

@xnuinside
Copy link
Owner

@hubg398 I think, I didn't add INDEX in column definition at all, I will add it, maybe today with patch release

@xnuinside
Copy link
Owner

xnuinside commented May 22, 2024

@hubg398 INDEX support in column definition released in version 1.5.1 - #258. I just published release - https://pypi.org/project/simple-ddl-parser/. If will be needed anything else - feel free to open the new one issue.

@hubg398
Copy link
Author

hubg398 commented May 23, 2024

🙏 Super appreciative of it, tested and works like a charm, thanks!

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

2 participants