I have the following query in my pipeline:
where([e], fragment("?->>? = ?", e.fields, ^field_name, ^field_value))
e
in this case stands for event
. What is the first parameter of the fragment method call doing?
The first parameter of the call to Ecto.Query.API.fragment/1
is the template for the fragment to be send to the database.
Here it is a Postgres function to retrieve a JSON object field as text. That said,
fragment("?->>? = ?", e.fields, ^field_name, ^field_value)
is literally “where nested field with a name field_name
in the JSONB field has a value equal to field_value
.”