Skip to content

Commit

Permalink
added postgresql cast in generated always expression
Browse files Browse the repository at this point in the history
  • Loading branch information
xnuinside committed May 9, 2024
1 parent c13ad11 commit 3a3815c
Show file tree
Hide file tree
Showing 13 changed files with 26,242 additions and 25,005 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
**v1.2.0**
### Fixes
MySQL:
1. Fixed issue relative to auto_increment that caused empty output if auto_increment defined in table properties -
https://github.com/xnuinside/simple-ddl-parser/issues/206

### Improvements
MySQL:
1. auto_increment added as property to mysql output

Oracle:
1. Added support for constraint name in column definition - https://github.com/xnuinside/simple-ddl-parser/issues/203
2. Added support for GENERATED (ALWAYS | (BY DEFAULT [ON NULL])) AS IDENTITY in column definition

PostgreSQL:
1. Added support for CAST statement in column GENERATE ALWAYS expression - https://github.com/xnuinside/simple-ddl-parser/issues/198


**v1.1.0**
### Improvements
MySQL:
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,24 @@ for help with debugging & testing support for BigQuery dialect DDLs:


## Changelog
**v1.2.0**
### Fixes
MySQL:
1. Fixed issue relative to auto_increment that caused empty output if auto_increment defined in table properties -
https://github.com/xnuinside/simple-ddl-parser/issues/206

### Improvements
MySQL:
1. auto_increment added as property to mysql output

Oracle:
1. Added support for constraint name in column definition - https://github.com/xnuinside/simple-ddl-parser/issues/203
2. Added support for GENERATED (ALWAYS | (BY DEFAULT [ON NULL])) AS IDENTITY in column definition

PostgreSQL:
1. Added support for CAST statement in column GENERATE ALWAYS expression - https://github.com/xnuinside/simple-ddl-parser/issues/198


**v1.1.0**
### Improvements
MySQL:
Expand Down
30 changes: 30 additions & 0 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,36 @@ for help with debugging & testing support for BigQuery dialect DDLs:
Changelog
---------

**v1.2.0**

Fixes
^^^^^

MySQL:


#. Fixed issue relative to auto_increment that caused empty output if auto_increment defined in table properties -
https://github.com/xnuinside/simple-ddl-parser/issues/206

Improvements
^^^^^^^^^^^^

MySQL:


#. auto_increment added as property to mysql output

Oracle:


#. Added support for constraint name in column definition - https://github.com/xnuinside/simple-ddl-parser/issues/203
#. Added support for GENERATED (ALWAYS | (BY DEFAULT [ON NULL])) AS IDENTITY in column definition

PostgreSQL:


#. Added support for CAST statement in column GENERATE ALWAYS expression - https://github.com/xnuinside/simple-ddl-parser/issues/198

**v1.1.0**

Improvements
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "simple-ddl-parser"
version = "1.1.0"
version = "1.2.0"
description = "Simple DDL Parser to parse SQL & dialects like HQL, TSQL (MSSQL), Oracle, AWS Redshift, Snowflake, MySQL, PostgreSQL, etc ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc.; sequences, alters, custom types & other entities from ddl."
authors = ["Iuliia Volkova <[email protected]>"]
license = "MIT"
Expand Down
5 changes: 4 additions & 1 deletion simple_ddl_parser/ddl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ def exceptional_cases(self, value: str) -> bool:

def t_AUTOINCREMENT(self, t: LexToken):
r"(?i:AUTO_INCREMENT|AUTOINCREMENT)\b"
t.type = "AUTOINCREMENT"
if not self.lexer.after_columns:
t.type = "AUTOINCREMENT"
else:
t.type = "ID"
return self.set_last_token(t)

def t_ID(self, t: LexToken):
Expand Down
7 changes: 7 additions & 0 deletions simple_ddl_parser/dialects/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@ def p_expr_index(self, p: List) -> None:
"""expr : expr ID INDEX"""
p[0] = p[1]
p[0][f"{p[2].lower()}_index"] = True

def p_generated_by(self, p: List) -> None:
"""generated_by : GENERATED BY DEFAULT ON NULL AS ID
| GENERATED BY ID AS ID
| GENERATED BY DEFAULT AS ID"""
p_list = list(p)
p[0] = {"generated_by": " ".join(p_list[3:]).upper()}
8 changes: 8 additions & 0 deletions simple_ddl_parser/dialects/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ def p_defcolumn(self, p: List) -> None:
| defcolumn option_with_tag
| defcolumn option_with_masking_policy
| defcolumn as_virtual
| defcolumn constraint
| defcolumn generated_by
"""
p[0] = p[1]
p_list = list(p)
Expand Down Expand Up @@ -1387,11 +1389,15 @@ def p_f_call(self, p: List) -> None:
| id LP f_call RP
| id LP multi_id RP
| id LP pid RP
| id LP id AS id RP
"""
p_list = list(p)
if isinstance(p[1], list):
p[0] = p[1]
p[0].append(p_list[-1])
elif p_list[1].upper() == "CAST":
p_list = remove_par(p_list)
p[0] = {"cast": {"value": p_list[2], "as": p_list[4]}}
else:
value = ""
for elem in p_list[1:]:
Expand All @@ -1410,6 +1416,8 @@ def p_multi_id(self, p: List) -> None:
if isinstance(p[1], list):
p[0] = p[1]
p[0].append(p_list[-1])
elif isinstance(p_list[1], dict):
p[0] = p[1]
else:
value = " ".join(p_list[1:])
p[0] = value
Expand Down
3 changes: 3 additions & 0 deletions simple_ddl_parser/output/dialects.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class MySSQL(Dialect):
default_charset: Optional[str] = field(
default=None, metadata={"exclude_if_not_provided": True}
)
auto_increment: Optional[str] = field(
default=None, metadata={"exclude_if_not_provided": True}
)


@dataclass
Expand Down
Loading

0 comments on commit 3a3815c

Please sign in to comment.