Slide 23
Slide 23 text
SQL変換ツール内容
23
import re
date_diff_re = re.compile('(.*)¥ (DATE_DIFF)(.*)', re.IGNORECASE) # 変換パターンごとに正規表現を用意
for line in src_sql: # 変換元のSQLを全行見ていく
sql = line.rstrip()
result = date_diff_re.match(sql)
if result:
pre = result.group(1)
clause = result.group(2)
sql = f"DATEDIFF{clause}" # DATE_DIFFをDATEDIFFに置換
comment = append_comment(comment, pre + clause, no_comments)
DATE_DIFFをDATEDIFFに変換する例
SELECT
DATE_DIFF(minute, x_hour, y) AS diff,
FROM ...
SELECT
DATEDIFF(minute, x_hour, y) AS diff,
FROM ...