title: Datetime syntax error with Psycopg2
body: <p>I'm trying to use Python datetime objects in my queries to a Postgres database using Psycopg2, but I have the following error : </p>
  
  <p>The code : </p>
  
  <pre><code># createdat is a datetime variable I used before
  print(type(createdat))
  
  q = """
      select created_at
      from mytable t
      and t.created_at &lt; %(createdat)s
      """ % {
          'createdat' : createdat
          }
  
  read.execute(q)
  </code></pre>
  
  <p>Returns :</p>
  
  <pre><code>&lt;type 'datetime.datetime'&gt;
  
  Traceback (most recent call last):
    File "import.py", line 346, in &lt;module&gt;
      read.execute(q)
    File "/usr/lib/python2.7/dist-packages/psycopg2/extras.py", line 120, in execute
      return super(DictCursor, self).execute(query, vars)
  psycopg2.ProgrammingError: syntax error at or near "20"
  LINE 6:         and created_at &lt; 2015-05-05 20:22:22
  </code></pre>
  
  <p>Any idea ? Thanks in advance</p>