如何在所有表 (PostgreSQL) 中搜索特定值? [英] How to search a specific value in all tables (PostgreSQL)?

查看:45
本文介绍了如何在所有表 (PostgreSQL) 中搜索特定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在每个表的每一列中搜索 PostgreSQL 中的特定值?

Is it possible to search every column of every table for a particular value in PostgreSQL?

这里有一个类似的问题 用于 Oracle.

A similar question is available here for Oracle.

推荐答案

转储数据库内容,然后使用grep怎么样?

How about dumping the contents of the database, then using grep?

$ pg_dump --data-only --inserts -U postgres your-db-name > a.tmp
$ grep United a.tmp
INSERT INTO countries VALUES ('US', 'United States');
INSERT INTO countries VALUES ('GB', 'United Kingdom');

相同的实用程序 pg_dump 可以在输出中包含列名.只需将 --inserts 更改为 --column-inserts.这样您也可以搜索特定的列名.但如果我要查找列名,我可能会转储模式而不是数据.

The same utility, pg_dump, can include column names in the output. Just change --inserts to --column-inserts. That way you can search for specific column names, too. But if I were looking for column names, I'd probably dump the schema instead of the data.

$ pg_dump --data-only --column-inserts -U postgres your-db-name > a.tmp
$ grep country_code a.tmp
INSERT INTO countries (iso_country_code, iso_country_name) VALUES ('US', 'United  States');
INSERT INTO countries (iso_country_code, iso_country_name) VALUES ('GB', 'United Kingdom');

这篇关于如何在所有表 (PostgreSQL) 中搜索特定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆