simple-ddl-parser icon indicating copy to clipboard operation
simple-ddl-parser copied to clipboard

Parsing of INDEX or UNIQUE KEY within CREATE TABLE statements

Open hubg398 opened this issue 1 year ago • 5 comments

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.

hubg398 avatar May 15 '24 14:05 hubg398

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

xnuinside avatar May 15 '24 14:05 xnuinside

@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 avatar May 18 '24 21:05 xnuinside

I fixed the first case in PR https://github.com/xnuinside/simple-ddl-parser/pull/256 and released version 1.5.0

xnuinside avatar May 18 '24 21:05 xnuinside

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?

hubg398 avatar May 19 '24 11:05 hubg398

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

xnuinside avatar May 19 '24 12:05 xnuinside

@hubg398 INDEX support in column definition released in version 1.5.1 - https://github.com/xnuinside/simple-ddl-parser/pull/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.

xnuinside avatar May 22 '24 18:05 xnuinside

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

hubg398 avatar May 23 '24 14:05 hubg398