SQL 字符串格式化程序 [英] SQL string formatter

查看:25
本文介绍了SQL 字符串格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道一个程序、实用程序或一些程序库,最好是用于 Linux,它采用未格式化的 SQL 字符串并漂亮地打印出来?

Does anyone know of a program, a utility, or some programmatic library, preferably for Linux, that takes an unformatted SQL string and pretty prints it?

例如,我想要以下内容

select * from users where name = 'Paul'

改成这样的

select * 
from users
where
   name = 'Paul'

确切的格式并不重要.我只需要一些东西来获取一个大的 SQL 字符串并将其分解成更易读的东西.

The exact formatting is not important. I just need something to take a large SQL string and break it up into something more readable.

推荐答案

查看 sqlparse.它是一个安装命令 sqlformat 的 Python 模块.用法很简单,例如:

Check out sqlparse. It is a Python module that installs the command sqlformat. Usage is simple, e.g.:

sqlformat --reindent --keywords upper --identifiers lower my_file.sql

我尝试了上述 CLI 替代方案,但是:

I tried the aforementioned CLI alternatives, but:

  • sqlinform 出来了,因为我想要一个开源 CLI 应用程序.
  • fsqlf 只有很少的功能(例如,缺少 create view).
  • sqlinform is out, because I want an open source CLI application.
  • fsqlf has only few features (create view is missing for example).

感谢 sqlformat 我什至了解到REF"是一个 SQL:2011 和 SQL:2008 中的保留关键字.

Thanks to sqlformat I even learned that "REF" is a reserved keyword in SQL:2011 and SQL:2008.

这篇关于SQL 字符串格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆