I have a webpage that allows a user to update some data, but the user can update all data or just part of the data, for example, one user can make the following update:
{key1: "value", key2: "value", key3: "value"}
But another user can update maybe just the key 1 field.
My question is, how can I construct the SQL statement such that I update the information that I get from the user
def update_info(data: dict, id: int):
query : """
UPDATE table
SET (the key/value pairs of the data)
WHERE id = %(id)s
"""
data["id"] = id
database_call(query,data)
I ask this because I know I can probably do it with a f string but I am worried of any kind of SQL injection, also, the data received has been already validated with cerberus.
psycopg2(hint: include the driver you are using) then see Sql.