Skip to content

Commit 9fdb870

Browse files
committed
fix semi column in comment
1 parent 3f1b82a commit 9fdb870

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pum/utils/execute_sql.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from psycopg.errors import SyntaxError
66

77
from pum.exceptions import PumSqlException
8+
import re
89

910
logger = logging.getLogger(__name__)
1011

@@ -40,7 +41,20 @@ def execute_sql(
4041
sql_code = sql_content
4142
else:
4243
sql_code = sql_content
43-
sql_code = sql_code.split(";")
44+
def split_sql_statements(sql):
45+
pattern = r'(?:[^;\'"]|\'[^\']*\'|"[^"]*")*;'
46+
matches = re.finditer(pattern, sql, re.DOTALL)
47+
statements = []
48+
last_end = 0
49+
for match in matches:
50+
end = match.end()
51+
statements.append(sql[last_end:end - 1].strip())
52+
last_end = end
53+
if last_end < len(sql):
54+
statements.append(sql[last_end:].strip())
55+
return [stmt for stmt in statements if stmt]
56+
57+
sql_code = split_sql_statements(sql_code)
4458
else:
4559
sql_code = [sql]
4660

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
ALTER TABLE pum_test_data.some_table RENAME COLUMN created_date TO created;
3-
COMMENT ON COLUMN pum_test_data.some_table.created IS 'A comment with quotes '' and a backslash \\';
3+
COMMENT ON COLUMN pum_test_data.some_table.created IS 'A comment with semi column; , quotes '' and a backslash \\';

0 commit comments

Comments
 (0)