title: sqlalchemy + postgresql hstore to string
body: <p>How do I convert an sqlalchemy hstore value to a string?</p>
  
  <pre><code>from sqlalchemy.dialects.postgresql import array, hstore
  
  hs = hstore(array(['key1', 'key2', 'key3']), array(['value1', 'value2', 'value3']))
  
  # this triggers sqlalchemy.exc.UnsupportedCompilationError
  str(hs)
  </code></pre>
  
  <p>I expect something like <code>"key1"=&gt;"value1", "key2"=&gt;"value2", "key3"=&gt;"value3"</code></p>
  
  <p>I would like to use an sqlalchemy api rather than write a custom string formatting function that approximates what I want. I'm working with a legacy code base that uses sqlalchemy: I need to preserve any internal quirks and escaping logic that formatting does.</p>
  
  <p>However, the existing code base uses sqlalchemy via an ORM table insert, while I want to directly convert an sqlalchemy hstore value to a string?</p>
  
  <p><strong><em>UPDATE</em></strong>: I am trying to do something like this:</p>
  
  <p>I have an existing table with schema</p>
  
  <pre><code>create table my_table
  (
      id bigint default nextval('my_table_id_seq'::regclass),
      ts timestamp default now(),
      text_col_a text,
      text_col_b text
  );
  </code></pre>
  
  <p>I want to get the following Python sqlalchemy code working:</p>
  
  <pre><code>str_value = some_function()
  # Existing code is building an sqlalchemy hstore and inserting
  # into a column of type `text`, not an `hstore` column.
  # I want it to work with hstore text formatting
  hstore_value = legacy_build_my_hstore()
  
  # as is this triggers error:
  # ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'hstore'
  return db_connection.execute(
      """
      insert into my_table(text_col_a, text_col_b) values (%s, %s)
      returning id, ts
      """,
      (str_value, hstore_value).first()
  </code></pre>