gpt4 book ai didi

Python sqlparse 没有正确地为每一列创建新行

转载 作者:行者123 更新时间:2023-12-05 06:10:57 32 4
gpt4 key购买 nike

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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com