1

To reset a column value to its default, the following SQL statement can be used:

update "<table>"
set "<column>" = default
where "<condition>"

However, I couldn't find how to get the same query with SQLAlchemy. It can be taken from column's definition, but the idea is to get a query as above.

Table.column.default  # ColumnDefault object
Oleh Rybalchenko
  • 6,998
  • 3
  • 22
  • 36

1 Answers1

2

To set a column value to its default just update it's value to text('default').

Check below:

import sqlalchemy as sa
session.query(Table).filter(filter_conditions).update({column_name: sa.text('default')}, synchronize_session=False)

# Above line will produce the following query
query="update table_name set column_name=default where filter_conditions;"

Hope this helps!!

HNMN3
  • 542
  • 3
  • 9