Creating postgres schemas using psycopg cur.execute
问题 My python application allows users to create schemas of their naming. I need a way to protect the application from sql injections. The SQL to be executed reads CREATE SCHEMA schema_name AUTHORIZATION user_name; The psycopg documentation (generally) recommends passing parameters to execute like so conn = psycopg2.connect("dbname=test user=postgres") cur = conn.cursor() query = 'CREATE SCHEMA IF NOT EXISTS %s AUTHORIZATION %s;' params = ('schema_name', 'user_name') cur.execute(query, params)