获取Postgresql SELECT查询中所有使用的表的列表 [英] Get a list of all used tables in a Postgresql SELECT query
本文介绍了获取Postgresql SELECT查询中所有使用的表的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以获取Postgesql中复杂的SELECT查询中使用的所有表,而无需使用实际的SQL解析器?版本9.5及更高版本将被使用.
Is there a way to get all the tables used in complex SELECT query in Postgesql without using an actual SQL parser? ver. 9.5 and above will be used.
推荐答案
尝试:
create or replace function get_query_tables(p_query text) returns text[] language plpgsql as $$
declare
x xml;
begin
execute 'explain (format xml) ' || p_query into x;
return xpath('//explain:Relation-Name/text()', x, array[array['explain', 'http://www.postgresql.org/2009/explain']])::text[];
end $$;
select get_query_tables('your query here');
这篇关于获取Postgresql SELECT查询中所有使用的表的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文