Re: SQL user function returning list for IN clause

2009-10-27 Thread Lawrence D'Oliveiro
In message c601fad6-8126-4f43- b768-62ad6e7ec...@r5g2000yqb.googlegroups.com, Felix wrote: I want to run a query like select * from table a, table b where a.foo IN foobar(b.bar) where foobar is a user function (registered by create_function in pysqlite3) returning a list of integers.

SQL user function returning list for IN clause

2009-10-16 Thread Felix
I am using the Python SQLite3 interface, but the question is probably general to python and SQL. I want to run a query like select * from table a, table b where a.foo IN foobar(b.bar) where foobar is a user function (registered by create_function in pysqlite3) returning a list of integers.

Re: SQL user function returning list for IN clause

2009-10-16 Thread Peter Otten
Felix wrote: I am using the Python SQLite3 interface, but the question is probably general to python and SQL. I want to run a query like select * from table a, table b where a.foo IN foobar(b.bar) where foobar is a user function (registered by create_function in pysqlite3) returning a

Re: SQL user function returning list for IN clause

2009-10-16 Thread Felix
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):

Re: SQL user function returning list for IN clause

2009-10-16 Thread Peter Otten
Felix wrote: 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

Re: SQL user function returning list for IN clause

2009-10-16 Thread pjcoup
On Oct 16, 9:50 am, Felix schle...@cshl.edu wrote: [snip] I could create a new table matching each row in b to all values of b.bar and use that to join but that would be inefficient and very redundant. [snip] Is foobar(b.bar) essentially static? (I'm guessing so if you considered this as an