postgresql中的多个搜索和结果

postgresql中的多个搜索和结果,sql,postgresql,Sql,Postgresql,我不确定是否可行,但这就是我用这些数据寻找的: id | name | email | address | ------------------+------------------------------------------------------ 1 | Jhon A | jhon@test.com | st jhon 33 |

我不确定是否可行,但这就是我用这些数据寻找的:

   id     |     name         |           email       |    address       | 
------------------+------------------------------------------------------
     1    | Jhon A           | jhon@test.com         |  st jhon 33      |
     2    | Jhonathan        | other@test.com        |  other address.  |  
     3    | Will             | will@test.com         |  miami           |
     4    | David            | davis@test.com        |  st jhon 33      |
需要一个查询来搜索“jhon”之类的搜索结果,如:

{name: [{record_with_id_1, record_with_id_2}], email: [{record_with_id_1}], address: [{record_with_id_4}] }
我知道我可以单独进行查询,但我需要这样做,并为大约6个不同的列获得单独的结果,所以我想知道是否可以在单个查询中进行查询


谢谢

嗯。您可以单独聚合每一列。我不确定实际结果的格式,因此我将使用数组:

select array_agg(id) filter (where name ilike '%jhon%') as matching_names,
       array_agg(id) filter (where email ilike '%jhon%') as matching_emails,
       array_agg(id) filter (where address ilike '%jhon%') as matching_addresses
from t;
   

它很管用,谢谢!