5

I have a JSON field in Postgres Table (Column name : UserDetails) [{"name":"UserName","status":"UserStatus","type":"UserType","number":"UserNumber"},{"name":"UserName1","status":"UserStatus1","type":"UserType1","number":"UserNumber1"}] Basically, an array of objects.

I want to query the column 'UserDetails' to fetch all users whose name contains 'UserName' in typeorm

So far I've achieved to query the exact match against the name field of the JSON column

providedUserName='UserName1'

query.andWhere(`user.userdetails ::jsonb @> '[{"name":"${providedUserName}"}]'`)

How can I query such that I add in a LIKE constraint to the name attribute from the JSON column?

By providing 'UserName' I would like to get list of all users whose name contains 'UserName', in this case it shall return both the values

Thank you

Jay Joshi
  • 55
  • 2
  • 7
  • 2
    Ancient history, but for future visitors, something like this should help: https://stackoverflow.com/questions/42918348/postgresql-json-like-query – DemiPixel Oct 13 '21 at 06:10

0 Answers0