sqlalchemy update column with an expression -
i want update row setting result of expression on column, ex:
mytable.query.filter_by(id=the_id).update({ "my_col": "(now() @ time zone 'utc')" }) this code give me following error :
(dataerror) invalid input syntax type timestamp: "(now() @ time zone 'utc')" line 1: ...12bf98a-1ee9-4958-975d-ee99f87f1d4a', my_col='(now() at... ^ 'update my_table set my_col=%(redeemed_at)s id = %(id_1)s' {'my_col': "(now() @ time zone 'utc')", this should translate in sql :
update my_table set my_col = (now() @ time zone 'utc') id = ?; this sql statement works when run console
the error because timestamp cannot string "(now() @ time zone 'utc')"
you try using text() function or func.now() or time in utc
db.func.timezone('utc', db.func.now())
edit:
you can try using synchronize_session 'evaluate' or,
since updating 1 row, can this:
mytable_row_obj = mytable.query.filter_by(id=the_id).one() mytable_row_obj.my_col = ... ever want put here ... session.commit()
Comments
Post a Comment