This is the code.
def create_user(self, id: str, password: str):
query=SQL(
"CREATE USER {id} WITH PASSWORD {password}".format(
id=id
password=password
)
)
try:
self.cur.execute(
query=query
)
except DuplicateObject:
print("{id} User already created.".format(id=id))
else:
print("{id} User create.".format(id=id))
in the code below
query=SQL(
"CREATE USER {id} WITH PASSWORD {password}".format(
id=id
password=password
)
)
I am trying to use the class of the sql module for the id and password variables of the query.
id=Identifier(id)
password=SQL(password)
like the code above.
Using identifiers and SQL will result in a syntax error.
Which class fits the id password variable?
password = sql.Literal(password). It is good idea to use thesqlmodule namespace, it makes it clearer where things are coming from.qry = sql.SQL("CREATE USER {id} WITH PASSWORD %s").format(id=sql.Identifier('dog'))then:cur.execute(qry, ['test']). Then the password string would be properly escaped.