我正在尝试从 ms sql server 迁移到 MariaDB,当 Nvarchar(Max) 与 MariaDB 不兼容时出现问题,解决方案是将其更改为 varchar(3000) 的脚本?
我写了这段代码,但我不确定是否存在更好的方法。
import re
import re
input_file = 'MSSQLSERVER.sql'
output_file = 'MYSQL.sql'
with open(input_file, 'r', encoding='utf-16') as f:
content = f.read()
content = re.sub(r'\[?nvarchar\]?\s*\(\s*max\s*\)', 'varchar(3000)', content, flags=re.IGNORECASE)
with open(output_file, 'w', encoding='utf-8') as f:
f.write(content)
#python ReplaceNavcharMax.py