SQLAlchemy GLOB
<p>I'm using SQLAlchemy over an SQLite backend and I want to perform the following sort of update: </p>

<pre><code>UPDATE Measurement SET MeasurementCampaign=? WHERE filename GLOB ?
</code></pre>

<p>But I can't find any equivalent GLOB functionality in the SQLAlchemy docs. I have quite a few wildcard expressions and I'd really rather not rewrite them. </p>

<p>I've tried using the SQL directly like this:</p>

<pre><code>session.query(Measurement).\
               filter("WHERE filename GLOB {}".format(wildcard)).update({...})
</code></pre>

<p>But I don't think that's right. Should I create a GenericFunction for "GLOB" and if so, how would I go about it?</p>

<p>As I say, I have many wildcards to evaluate, so if I can perform the update on them all in one go so much the better!</p>

<p>It turns out you can use the <a href="http://docs.sqlalchemy.org/en/latest/orm/internals.html?highlight=in_#sqlalchemy.orm.interfaces.PropComparator.op" rel="nofollow" title="op">'op'</a> function for exactly this:</p>

<pre><code>session.query(Measurement).filter(Measurement.filename.op('GLOB')(wildcard)).update({...})
</code></pre>

python sqlite sqlalchemy