如何解决需要查找记录,但只知道ID,而不是表
我想在我的PostgreSQL数据库中找到具有特定UUID的记录。不幸的是,我不知道它的表名,只知道它的UUID。
如何找到它?
解决方法
在psql
会话中,使用如下所示的DO
块,它将打印出找到您的uuid
的表:
do $$
declare
sdata record;
_count bigint;
begin
for sdata in select table_schema as tschema,table_name as tname,column_name as cname
from information_schema.columns
where data_type = 'uuid'
loop
execute format('select count(*) from %I.%I where %I = %L',sdata.tschema,sdata.tname,sdata.cname,<your uuid here>)
into _count;
if _count > 0 then
raise notice '%.% % %',_count;
end if;
end loop;
end
$$;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。