如何搜索所有表(PostgreSQL)中的特定值? [英] How to search a specific value in all tables (PostgreSQL)?
本文介绍了如何搜索所有表(PostgreSQL)中的特定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在PostgreSQL中搜索每个表的每一列作为特定值?
Is it possible to search every column of every table for a particular value in PostgreSQL?
类似的问题可用 here for 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可以在输出中包含列名。只需更改 - 插入
到 - 列插入
。这样您也可以搜索特定的列名称。但如果我在寻找列名,我可能会转储模式而不是数据。
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屋!
查看全文