Skip to content

Commit

Permalink
Closes #240
Browse files Browse the repository at this point in the history
Support functions with schema prefix in `DEFAULT` and `CHECK` statements.
  • Loading branch information
kliushnichenko committed Mar 23, 2024
1 parent b162a34 commit 7365634
Show file tree
Hide file tree
Showing 5 changed files with 581 additions and 50,807 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**v1.0.4**
### Improvements
1. Support functions with schema prefix in `DEFAULT` and `CHECK` statements.

**v1.0.3**
### Improvements
1. Fixed bug with `CREATE OR REPLACE SCHEMA`.
Expand Down
23 changes: 20 additions & 3 deletions simple_ddl_parser/dialects/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,6 +1429,7 @@ def p_default(self, p: List) -> None:
| DEFAULT LP pid RP
| DEFAULT LP funct_expr pid RP
| default id
| DEFAULT id DOT funct_expr
| default LP RP
"""
p_list = remove_par(list(p))
Expand All @@ -1448,8 +1449,11 @@ def p_default(self, p: List) -> None:

@staticmethod
def pre_process_default(p_list: List) -> Any:
if len(p_list) == 5 and isinstance(p_list[3], list):
default = p_list[3][0]
if len(p_list) == 5:
if isinstance(p_list[3], list):
default = p_list[3][0]
else:
default = f"{''.join(p_list[2:5])}"
elif "DEFAULT" in p_list and len(p_list) == 4:
default = f"{p_list[2]} {p_list[3]}"
else:
Expand Down Expand Up @@ -1523,20 +1527,33 @@ def p_check_st(self, p: List) -> None:
| check_st id RP
| check_st STRING RP
| check_st funct_args
| CHECK LP id DOT id
| check_st LP pid RP
"""
p_list = remove_par(list(p))
if isinstance(p[1], dict):
p[0] = p[1]
else:
p[0] = {"check": []}
for item in p_list[2:]:

i = 0
items = p_list[2:]
items_num = len(items)

while i < items_num:
item = items[i]
# handle <schema>.<function>
if i + 1 < items_num and items[i + 1] == ".":
p[0]["check"].append(f"{''.join(items[i:i + 3])}")
i += 3
continue
if isinstance(p_list[-1], dict) and p_list[-1].get("args"):
p[0]["check"][-1] += p_list[-1]["args"]
elif isinstance(item, list):
p[0]["check"].append(f"({','.join(item)})")
else:
p[0]["check"].append(item)
i += 1

def p_using_tablespace(self, p: List) -> None:
"""using_tablespace : USING INDEX tablespace"""
Expand Down
Loading

0 comments on commit 7365634

Please sign in to comment.