I have a table "profile" with a jsonb
field called "payment_methods".
The jsonb field structure is this:
[{"name": "paypal", "primary": false},
{"name": "braintree", "primary": true},
{"name": "skrill", "primary": false}]
I want to make a query to dynamically set the primary payment method to the method that user will choose. If the user choose the paypal method as primary, i want to set the jsonb
field like this:
[{"name": "paypal", "primary": true},
{"name": "braintree", "primary": false},
{"name": "skrill", "primary": false}]
So, i want to update the paypal's primary filed to true and any other payment method's primary field to false.
Notice: I want to filter with the name field. So if user give me for example paypal i want to set it as primary.
How can i do that?