Psycopg2 has been giving me this error whenever I try to update a row:
Traceback (most recent call last):
File "p:/Projects/Freelance/Optometry_Inventory/code/tester.py", line 39, in <module>
new_user.updateUser(*(fname, lname, username, role, hashed_pwd, user_id))
File "p:\Projects\Freelance\Optometry_Inventory\code\UserDC.py", line 64, in updateUser
cursor.execute(update_query, args)
psycopg2.errors.SyntaxError: syntax error at or near "lname"
LINE 1: UPDATE users SET fname= ('a'), SET lname= ('b'),
When I run the following function:
def updateUser(self, user_id):
self.user_id = user_id
update_query = """UPDATE users SET fname= %s, SET lname= (%s),
SET username= (%s), SET user_role= (%s), SET h_pwd= (%s), WHERE user_id= (%s)"""
with pool() as cursor:
cursor.execute(update_query, (self.fname, self.lname, self.user_name,
self.user_role, self.user_pwd, self.user_id))
I have tried just updating a single field and I still get the same error. Is there something more I am missing? The error code isn't giving me much information.
SETat the beginning and you have to remove the comma before theWHERE. And you can get rid of the parentheses in your SQL statement.