[Ur] SQL table.field IN list

Simon Van Casteren simon.van.casteren at gmail.com
Sat Jan 12 09:13:32 EST 2019


Hi,

Am I correct in thinking that the standard library/compiler doesn't support
SQL "IN" statements? It's something that I use a lot in my programs, and in
psql for example you can just do:

SELECT *
FROM uw_lesson_lessons
WHERE uw_id in (1, 2, 3)

I made my own function to handle this, using a bunch of sql_or statements:

fun inlist
      [a ::: Type]
      [otherfields ::: {Type}]
      [tablename :: Name]
      [columnname :: Name]
      [otherfields ~ [columnname = a]]
      (_ : sql_injectable a)
      (ids: list a)
    : sql_exp ([tablename = [columnname = a] ++ otherfields]) ([]) ([]) bool
  =
  List.foldl
    (fn id acc => (SQL {acc} OR {{tablename}}.{columnname} = {[id]}))
    (WHERE {[False]})
    ids

I'm not sure about the performance characteristics of this though. Anyway,
just wondering if it is already supported but I can't find it, or it's not
supported at all?

Thanks

Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.impredicative.com/pipermail/ur/attachments/20190112/b6350dd1/attachment.html>


More information about the Ur mailing list