用例是,假设您有一个包含大量列(100+)的表,并且希望查看表中是否存在某个列名。另一个用例是,假设表中的列有一个名称方案,允许我搜索一个术语,该术语将显示带有该名称的所有字段--例如,与支付卡相关的所有字段都以"card_“为前缀。
在MySQL中,我可以通过执行show fields in <table_name> like '%<search_term>%'来处理上述两种情况。我搜索了一种解决方案,但只找到了与过滤实际表名和显示表模式(例如\d+)有关的结果,这不是我想要的结果。我还在psql中尝试了MySQL命令的变体,但没有成功。
我正在寻找一种使用SQL或其他Postgres内置方式来完成此操作的方法。现在,我诉诸于将表模式复制到文本文件并以这种方式进行搜索。
发布于 2015-12-28 16:43:37
您可以使用information_schema.columns和table_name查询column_name。例如:
>= select table_name, column_name
from information_schema.columns
where table_name = 'users'
and column_name like '%password%';
table_name | column_name
------------+------------------------
users | encrypted_password
users | reset_password_token
users | reset_password_sent_athttps://stackoverflow.com/questions/34497093
复制相似问题