I am currently working with PostgreSQL. I have a table called users
that includes a column titled preferences
of type JSONB
. An example shape of this column is as follows:
{
pets: ['Cat', 'Dog', 'Goldfish'],
cars: ['Sedan', 'Van'],
// Other keys; not relevant
}
Within TypeScript, I have created a function like the one below:
function removePetFromAllUsers(pet: string) {
// Sequelize query will go here
}
I am in need of a sequelize query that can update all entries in the users
table where the pets
array contains the given parameter string. Specifically, any user whose preferred pet is "Dog" should have that removed from their preferences.pets
array.
How do I go about crafting this query?
The desired outcome is to update all rows in which preferences.pets
includes the string pet
, ensuring that the updated entries no longer contain that string.