Having a special character such as a period in a python key
<p>I'm trying to generate sql insert statements using sqlalchemy like this.</p>

<pre><code>def get_sql(self):
    """Returns SQL as String"""
    baz_ins = baz.insert().values(
        Id=self._id,
        Foo.Bar=self.foo_dot_bar,
    )
    return str(baz_ins.compile(dialect=mysql.dialect(),
                             compile_kwargs={"literal_binds": True}))
</code></pre>

<p>This returns <code>keyword cannot be expression</code>. Escaping the period like <code>\.</code> also doesn't work.</p>

<p>One solution I came up with is using <code>FooDOTBar instead of Foo.Bar</code> and then replacing all "DOT" with "." in the generated sql files, this corrupts some other data though and is not optimal. Any better suggestions to deal with this from the ground up?</p>

<p>There's an alternate form of <a href="http://docs.sqlalchemy.org/en/latest/core/dml.html#sqlalchemy.sql.expression.ValuesBase.values" rel="nofollow"><code>.values</code></a> where you pass in a <code>dict</code> instead:</p>

<pre><code>baz.insert().values({
    "Id": self._id,
    "Foo.Bar": self.foo_dot_bar,
})
</code></pre>

python sqlalchemy