Q:

Datetime with postgresql, python, and a stored procedure

I have a stored procedure that contains this line:
EXECUTE FORMAT('SELECT * FROM stores.paint WHERE created >= %s... where %s is filled in by a parameter: dt TIMESTAMP.
I am calling this from the python console:
conn = psycopg2.connect(host=host, database=db, user=user, password=pass)
 r = conn.cursor()
 r.callproc('procedure_name', [datetime.datetime.now()])

I get an error due to the space in the datetime / timestamp:
psycopg2.ProgrammingError: syntax error at or near "15"
 LINE 1: ...* FROM stores.paint WHERE created >= 2015-02-21 15:20:40.2...
                                                            ^

I have tried using single quotes in the stored procedure.  This results in it using a literal %s in the query string.
So, how can I pass a parameter to a stored procedure that has a space in it, so that the query actually works?

A:

Escape the string with single quotes to make it proper SQL:
FORMAT('... created >= ''%s'' ...')

