我想从“FROM”和“JOIN”中获取表名。这是查询的示例:
SELECT * FROM film JOIN language ON film.language_id = language.language_id WHERE language_name = "English"
我在 python 中使用 sqlparse 库。这是我试过的:
line="FROM film INNER JOIN language ON film.language_id =
language.language_id WHERE language.name = 'English' GROUP BY language_id"
a = sqlparse.parse(line)[0].tokens
print (a)
Out[91]:
[<Keyword 'FROM' at 0x1EEA18CDAC8>,
<Whitespace ' ' at 0x1EEA18CDCA8>,
<Identifier 'film' at 0x1EEA18CE6D8>,
<Whitespace ' ' at 0x1EEA18CDB28>,
<Keyword 'INNER ...' at 0x1EEA18CDBE8>,
<Whitespace ' ' at 0x1EEA18CDC48>,
<Keyword 'langua...' at 0x1EEA18CDA68>,
<Whitespace ' ' at 0x1EEA18CDD08>,
<Keyword 'ON' at 0x1EEA18CDD68>,
<Whitespace ' ' at 0x1EEA18CDDC8>,
<Comparison 'film.l...' at 0x1EEA18CE7C8>,
<Whitespace ' ' at 0x1EEA18B61C8>,
<Where 'WHERE ...' at 0x1EEA18CE4F8>,
<Keyword 'GROUP ...' at 0x1EEA18B65E8>,
<Whitespace ' ' at 0x1EEA18B6648>,
<Identifier 'langua...' at 0x1EEA18CE750>]
我期望的输出:
table = [film,language]
有人可以帮助我吗?谢谢