SQL解析器识别SQL内部使用的表

发布于 2025-01-26 03:20:29 字数 221 浏览 1 评论 0原文

我正在寻找一种解决方案,以识别SQL查询中使用的表列表。我可以使用Unix Shell脚本找到表名。但是要确定哪个表是强制性的(内联节表)&不是(左连接表) - 基本的外壳脚本没有太大帮助,因为复杂的SQL场景太多(嵌套子查询,左JOIN 关键字之后是子查询具有内在的联接)。

有任何指示可以达到要求吗?

I am looking for a solution to identify list of tables used in a SQL query. I am able to find the table names using Unix shell scripting. but to identify which table is mandatory (inner join tables) & which are not (left join tables) - basic shell scripting is not helping much as there are too many complex SQL scenario (Nested subquery , left join keyword is followed by a subquery which has inner join ).

any pointers to achieve the requirement ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悲凉≈ 2025-02-02 03:20:29

您可以使用 sqlglot

import sqlglot 
import sqlglot.expressions as exp

sqlglot.parse_one("select * from x join y").find_all(exp.Table)

从那里,您将获得所有表节点的列表检查父母以查看是否符合您的条件。

You can use SQLGlot

import sqlglot 
import sqlglot.expressions as exp

sqlglot.parse_one("select * from x join y").find_all(exp.Table)

From there, you'll get a list of all the table nodes which you can then check the parent to see if it fits your criteria.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文