xnuinside / simple-ddl-parser

Simple DDL Parser to parse SQL (HQL, TSQL, AWS Redshift, BigQuery, Snowflake and other dialects) ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc. & table properties, types, domains, etc.
MIT License
175 stars 40 forks source link

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

Closed hubg398 closed 2 months ago

hubg398 commented 2 months ago

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
);

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

xnuinside commented 2 months ago

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

xnuinside commented 2 months ago

@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 commented 2 months ago

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

hubg398 commented 2 months ago

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 commented 2 months ago

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

xnuinside commented 2 months ago

@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.

hubg398 commented 2 months ago

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