工具列表
- SQL格式化 Python 包 sqlparse壶栋,文檔地址
- 在線的 SQL 格式化工具:http://sqlformat.org/,基于上述python包搭建济竹,可以在線轉(zhuǎn)化
- sublime 插件
- SqlBeautifier
- Select Quoted蚕泽,sublime快速選擇引號(hào)內(nèi)容,可以使用該插件先選中引號(hào)中文本中跌,再用SqlBeautifier進(jìn)行格式化,快速實(shí)現(xiàn)SQL格式化菇篡。
示例
sqlparse
$ pip install sqlparse
$ python
>>> import sqlparse
>>> print(sqlparse.format("select * from (select a, b, sum(c) from foo where d = 1 and e in ('a', 'b') group by f) t1 join (select a, g from bar) t2 on t1.a = t2.a left outer join t3 on t1.a = t3.a", reindent=True, keyword_case='upper'))
SELECT *
FROM
(SELECT a,
b,
sum(c)
FROM foo
WHERE d = 1
AND e IN ('a',
'b')
GROUP BY f) t1
JOIN
(SELECT a,
g
FROM bar) t2 ON t1.a = t2.a
LEFT OUTER JOIN t3 ON t1.a = t3.a
Sublime插件
安裝SqlBeautifier
和Select Quoted
后漩符,即可使用cmd + '
快速選中文本,再用cmd + k, cmd + f
進(jìn)行格式化驱还。