I am trying to use split method in sqlparse module to split the queries file into queries list. When I use, 'create procedure' query, it is splitting correctly. But when I use 'replace procedure', it is splitting a single query into two queries. It is splitting with semicolon and ignoring begin and end.
import sqlparse
from sqlparse.keywords import *
query = """REPLACE PROCEDURE u1.SP_Employee (
IN EmpNo INTEGER, IN EmpName INTEGER
)
BEGIN
INSERT INTO u1.employee (
EmpNo,
EmpName
)
VALUES (
:EmpNo,
:EmpName
);
END;
"""
sql_formats = sqlparse.format(query,strip_comments=True, reindent=True)
result = sqlparse.parse(query)
for i in range(0,len(result)) :
print("index is "+str(i))
print(result[i])
print("Result printing is done for replace query")
query = """create PROCEDURE u1.SP_Employee (
IN EmpNo INTEGER, IN EmpName INTEGER
)
BEGIN
INSERT INTO u1.employee (
EmpNo,
EmpName
)
VALUES (
:EmpNo,
:EmpName
);
END;
"""
sql_formats = sqlparse.format(query,strip_comments=True, reindent=True)
result = sqlparse.parse(query)
for i in range(0,len(result)) :
print("index is `enter code here`"+str(i))
print(result[i])
print("Result printing is done for create query")
**Output :-**
index is 0
REPLACE PROCEDURE u1.SP_Employee (
IN EmpNo INTEGER, IN EmpName INTEGER
)
BEGIN
INSERT INTO u1.employee (
EmpNo,
EmpName
)
VALUES (
:EmpNo,
:EmpName
);
index is 1
END;
index is 2
Result printing is done for replace query
index is 0
create PROCEDURE u1.SP_Employee (
IN EmpNo INTEGER, IN EmpName INTEGER
)
BEGIN
INSERT INTO u1.employee (
EmpNo,
EmpName
)
VALUES (
:EmpNo,
:EmpName
);
END;
index is 1
Result printing is done for create query