Postgresql filter by element in array of object

Viewed 23

I have 2 table Vaults and Wallets (there are many wallets in a vault) and this is basically my current query

SELECT vault.id, array_agg(json_build_object('id',wallet.id,'value',wallet.value)) AS wallets
FROM vault 
LEFT JOIN wallet
GROUP BY vault.id

Now I want to search for vaults by wallet name. How can I write the SQL query for this problem? For example a search using keyword: BTC will return a vault like this: {id: 1, wallets: [{id: 1, name: "BTC"},{id:2, name: "ETH"}]}

Also, I'm currently using TypeORM with NestJS

0 Answers
Related