作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Python中解析SQL常用的包是sqlparse
:
pip3 install --user sqlparse
我想解析 create table
语句的列表,库有时会创建新行但缩进错误:
import sqlparse;
print(sqlparse.format("create table (id int,foo text, bar float)", reindent=True, keyword_case="upper"));
每一行的缩进越来越多,这使得 SQL 文本看起来断断续续。如何告诉 sqlparse
正确缩进?也尝试过 reindent_aligned=True
但没有用。
最佳答案
你可以试试我的图书馆SQLGlot
python -m sqlglot "create table x (id int,foo text, bar float)"
CREATE TABLE x (
"id" INT,
"foo" TEXT,
"bar" FLOAT
)
关于Python sqlparse 没有正确地为每一列创建新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64169212/
Python中解析SQL常用的包是sqlparse: pip3 install --user sqlparse 我想解析 create table 语句的列表,库有时会创建新行但缩进错误: impor
我有两个不同的 Django 项目。一种使用 PostgreSQL,一种使用 MySQL。 在 postgres 版本中,这有效。 migrations.RunSQL('''CREATE OR
我有一个很大的请求,我尝试使用 sqlparse 通过 python 程序解析它。 这是代码: import sqlparse req1 = """select qty, end_date from
我是一名优秀的程序员,十分优秀!