I'm trying to update user credentials for PostgreSQL db user using Python. I've tried referring to the following thread but that doesn't seem to solve my issue unfortunately:
How to change password of a newly created user using variable in postgresql 9.5 SP
Here's my code:
con = p.connect(database="mydB", user="abc", password="testing", host="127.0.0.1", port="5432")
cur = con.cursor()
uid = "adi"
pwd = "test6"
statement = statement = '''CREATE or REPLACE FUNCTION add_user ({}, {}) RETURNS void AS $$ EXECUTE ALTER USER ' || $1 || ' WITH PASSWORD || $2||'''.format(uid,pwd)
cur.execute( statement)
cur.execute('''COMMIT''')
I get the following error: ProgrammingError: syntax error at or near "'adi'"
Please help or refer me to a thread with a better solution. Thanks in advance, everyone!