Say I have a table 'testing' with a column 'agents' of type jsonb
that stores an array of agent names
> SELECT * FROM testing;
+--------------------------------------+---------------------+
| id | agents |
|--------------------------------------+---------------------|
| 018d17a4-5418-1f87-f702-3ed8325f4d11 | ["mikel", "arsene"] |
+--------------------------------------+---------------------+
I can use the ?
operator to find records that have a string as one of the agents.
> SELECT * FROM testing WHERE agents ? 'mikel'
+--------------------------------------+---------------------+
| id | agents |
|--------------------------------------+---------------------|
| 018d17a4-5418-1f87-f702-3ed8325f4d11 | ["mikel", "arsene"] |
+--------------------------------------+---------------------+
However, in gorm the ?
also acts as a placeholder. So I can't form the query as
query := `SELECT * FROM testing WHERE agents ? ?
gorm.Raw(query, 'mikel')
will produce the raw query
SELECT * FROM testing WHERE agents 'mikel' ?
I know I could use the @>
operator to achieve this but I would like to know how I can specifically use the ?
operator
jsonb_exists
instead of?
– Guilder@>
. Did you check the duplicate? – Guilder?
operator itself just out of curiosity. I have solved using@>
operator in my case. – Epicene?
operator is simply erased by gorm. – Epicene?
to any equivalent function, you'll lose index support - those are tied to operator classes. I thinkpostgres
was in the title from the start. Did you try duplicating the?
to??
or even???
? – Rescue??
were erased by gorm. – Epicene