title: Python-Sqlalchemy Binary Column Type HEX() and UNHEX() with autoloaded table
body: <p>We use sqlalchemy and inserts and updates works fine, but now we want migrate UUID from varchar to varbinary. How to do this?</p>
  
  <p>Example of code now:</p>
  
  <pre><code>engine = create_engine(dburi, echo = True, pool_size=100, pool_recycle=7200)
  db_session = scoped_session(sessionmaker(autocommit=True, bind=engine))
  metadata = MetaData(engine)
  conn = engine.connect()
  ....
  table = Table("table", metadata, autoload=True)
  result = db_session.execute(table.insert(), {"uuid":func.UNHEX("AABBCCDD"})
  </code></pre>
  
  <p>In output i see </p>
  
  <p>INFO sqlalchemy.engine.base.Engine ('unhex(:unhex_1)',) and in db - not result of UNHEX but UNHEX(:UNHEX_1)</p>
  
  <p>I have seen <a href="https://stackoverflow.com/questions/33923914/python-sqlalchemy-binary-column-type-hex-and-unhex/33925980">Python-Sqlalchemy Binary Column Type HEX() and UNHEX()</a> but i cannot comment this and cannot understand what if we <em>load</em> structure, not generate it in class. Use db_sesson.execute().filter()? And how to updates when we need "where uuid=UNHEX(?)" ?</p>
  
  <p>Now if i write as uuid=binascii.unhexlify(uuid), save to varbinary(32) - works, to varchar(64) with table charset=utf8 works, to carchar with charset=ascii - exception</p>
  
  <pre><code>OperationalError: (_mysql_exceptions.OperationalError) (1366, "Incorrect string value: '\\xDB\\xE7,\\x98\\xF9\\x11...' for column 'uuid' at row 1") [SQL: u'INSERT INTO callrec (record_dt, dealer_id, client_id, extension_id, caller_id, destination, file_size, record_url, uuid, record_path, duration) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'] [parameters: (datetime.datetime(2015, 12, 2, 13, 33, 51), u'1', u'12', u'6', u'000*102', u'000*103', 67244, u'', 'P\xdb\xe7,\x98\xf9\x11\xe5\xb8\x9e\xd3\xb2v\xc0\xccZ', '', 2)]
  </code></pre>
  
  <p>But manual write as uuid=UNHEX("AABBCCDD") already works!</p>