postgresql - Python 3 how to UPDATE TIMESTAMPTZ? -
please update table column type timestamptz.
table this
table( table_id serial primary key, table_name varchar(35) not null, last_update timestamptz default now(), table_link varchar(70) not null, table_tracking boolean default true, url varchar(225) not null ) code update table
cur.execute("set timezone='us/pacific'; select now()") time_db = cur.fetchall() last_update = time_db[0][0] cur.execute(""" update table set last_update = {}, table_tracking = {} id = {}; """.format(last_update, tracking, id)) error.args in console
('syntax error @ or near "10"\nline 5: last_update = 2017-07-28 10:17:55.523070')
the problem here 2017-07-28 10:17:55.523070 interpreted arithmetic expression - 2017 - 7 - 28 == 1982. when gets 10:17:55.523070 part, parser has not idea it.
in order have interpreted timestampz value, need escape '2017-07-28 10:17:55.523070'. however, doing manually bad idea various reasons. database connection package should you:
cur.execute(""" update table set last_update = %(last_update)s, table_tracking = %(table_tracking)s id = %(id)s; """, { "last_update": last_update, "table_tracking": tracking, "id": id, } ) more information in documentation
Comments
Post a Comment