SQL user function returning list for IN clause

Felix schlesin at cshl.edu
Fri Oct 16 13:15:23 EDT 2009


> > Rewriting the query to say
> > select * from table a, table b where foobar_predicate(a.foo, b.bar)
> > would work (foobar_predicate checks if a.foo is in foobar(b.bar). But
> > it does not allow to use an index on a.foo

> Define a function foobar_contains() as follows:
>
> def foobar_contains(foo, bar):
>     return foo in foobar(bar)
>
> and change the query to
>
> select * from table a, table b where foobar_contains(a.foo, b.bar)

I thought about that (see above), but it would not use an index on
a.foo which a regular a.foo IN (x,y,z) does.

Felix



More information about the Python-list mailing list