搜索整个postgres数据库?

编程入门 行业动态 更新时间:2024-10-22 23:41:30
本文介绍了搜索整个postgres数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个庞大的数据库,我不介意离开搜索一段时间,但是由于各种原因,我无法转储整个数据库。我能写出的最简单的查询是什么,它将查询数据库中所有表的所有字段以查找特定的文本字符串?

I have a massive database that I don't mind leaving to search for a while, but I can't dump the whole database for various reasons. What is the easiest query I can write that will search all fields of all tables in a database for a specific string of text?

以下内容将不起作用,但应显示我希望看到的内容:

The following won't work but should demonstrate what I would like to see:

SELECT * FROM * where * like '%mystring%'

有什么想法吗?

推荐答案

您可以利用以下事实:在PostgreSQL中,表名。*

You could take advantage of the fact that in PostgreSQL, tablename.* can be cast to text.

因此, SELECT t。* FROM表名t WHERE(t。*):: text像'%somestring %'将返回任何列包含 somestring 的行,无论该列的类型如何。

So, SELECT t.* FROM tablename t WHERE (t.*)::text LIKE '%somestring%' will return any row where any column contains somestring, no matter what the type of the column.

如果在 SELECT table_schema,table_name FROM information_schema 的循环中使用,它可与 grep 媲美在数据库转储中,除非您不需要转储。

If used in a loop on SELECT table_schema, table_name FROM information_schema, it's comparable to a grep within a database dump, except you don't need the dump.

更多推荐

搜索整个postgres数据库?

本文发布于:2023-08-05 21:30:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1308164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   postgres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!