'Error when trying to update timestamp in database
Code:
resultdate = datetime.now().replace(minute= 0,second=0, microsecond=0)
global usrid
usrid = message.from_user.id
up.uses_netloc.append("postgres")
url = up.urlparse(os.environ['DATABASE_URL'])
conn = psycopg2.connect(database=url.path[1:],
user=url.username,
password=url.password,
host=url.hostname,
port=url.port
)
cursor = conn.cursor()
cursor.execute('INSERT into kazino (usr_id, game_time) VALUES (%s, %s) ON CONFLICT DO UPDATE SET game_time = %s WHERE usr_id = %s);', (usrid, resultdate, resultdate, usrid, ))
conn.commit()
When I'm inserting info it`s alright but when I try to update it gives an error:
cursor.execute('INSERT into kazino (usr_id, game_time) VALUES (%s, %s) ON CONFLICT DO UPDATE SET game_time = %s WHERE usr_id = %s);', (usrid, resultdate, resultdate, usrid, )) psycopg2.errors.SyntaxError: syntax error at or near ")" LINE 1: ... '2022-05-17T13:00:00'::timestamp WHERE usr_id = 578408714);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|