title: Dynamic named parameters in Groovy?
body: <p>I found it really cool that in Groovy SQL it is possible to do this:</p>
  
  <pre><code>def resultList = Domain.executeQuery('select * from languages where name = :name', [name: 'Groovy'])
  </code></pre>
  
  <p>I am trying to get the HQL "in" keyword to work with a dynamic list used as the argument, not a fixed list.</p>
  
  <p>I also know that you can use the "?" operator for your SQL parameters instead of using named parameters. However according to this question:</p>
  
  <p><a href="https://stackoverflow.com/questions/3126366/doing-an-in-query-with-hibernate">Doing an &quot;IN&quot; query with Hibernate</a></p>
  
  <p>The "in" keyword only supports named and positional parameters, not the "?" parameter. The problem is, when I try to do something like this:</p>
  
  <pre><code>def paramMap = [:]
  paramMap.put("name", "groovy")
  
     def resultList = Domain.executeQuery('select * from languages where name = :name', paramMap)
  </code></pre>
  
  <p>I get an error saying that I have not specified the parameter name. So it is acting as if I have not actually specified the parameter "name". I have read the Groovy documentation on named parameters here:</p>
  
  <p><a href="http://groovy.codehaus.org/api/groovy/sql/Sql.html" rel="nofollow noreferrer">http://groovy.codehaus.org/api/groovy/sql/Sql.html</a></p>
  
  <p>But all of the examples using named parameters use a predefined parameter list. I have searched and have not found an example of using a dynamic parameter list map. How can I pass a dynamic map of parameters into Groovy named SQL query? If that is not possible, how can I use the "in" keyword with a dynamic list?</p>
  
  <p>To be clear, I am constructing a dynamic SQL query and I would like to be able to add parameters to a map or list as I go along. I was previously using the "?" operator until I had to use the "in" clause, which does not work with "?".</p>