Using postgres in python,
How do I replace all fields from the same column that match a specified value? For example, let's say I want to replace any fields that match "green" with "red" in the "Color" column.
How to delete all fields from the same column that match a specified value? For example, I'm trying to deleted all fields that match "green" in the Color column.
Ad1. You need something like this:
session.query(Foo).filter_by(color = 'green').update({ 'color': 'red' })
session.commit()
Ad2. Similarly:
session.query(Foo).filter_by(color = 'green').delete()
session.commit()
You can find the querying documentation here and here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With