Rectangle 27 0

python Pass dynamic database function to psycopg2 cursor.execute(statement, params)?


if multi:
    mygeom = "ST_Multi(ST_GeomFromGml(%s))"
else:
    mygeom = "ST_GeomFromGml(%s)"

self.cursor.execute( """INSERT INTO {}.parcel (
    id,geometry) VALUES (%s, {})""" .format(self.config.schema, mygeom) , (self.id, self.geometry) )

I inserted the schema and function with a string format method. I also inserted self.geometry in a safe way.

Note
Rectangle 27 0

python Pass dynamic database function to psycopg2 cursor.execute(statement, params)?


if multi:
    mygeom = "ST_Multi(ST_GeomFromGml(%s))"
else:
    mygeom = "ST_GeomFromGml(%s)"

self.cursor.execute( """INSERT INTO {}.parcel (
    id,geometry) VALUES (%s, {})""" .format(self.config.schema, mygeom) , (self.id, self.geometry) )

I inserted the schema and function with a string format method. I also inserted self.geometry in a safe way.

Note