in my golang project I use postgres with gorm and I have an attributes column with the following json:
{"email": ["[email protected]", "[email protected]", "[email protected]"], "mail_folder": "some_folder"}
{"email": ["[email protected]", "[email protected]", "[email protected]"], "mail_folder": "some_folder"}
So I need to get a record which contains email [email protected] which is the first one. I can extract it with plain sql in sql editor with the following query:
select * from authors a where attributes @> '{"email": ["[email protected]"]}';
but in gorm I keep getting wrong json syntax errors etc. I tried to do it with Raw() query or with
Where(fmt.Sprintf("attributes ->> 'email' = '[\"%v\"]'", email)).
but it did not work either. Any ideas how to fix it would be welcome. Thank you.