Groovy sql.firstRow() 中的字符串

Groovy string in sql.firstRow()

这个有效:

def sql = new Sql(dataSource)
def name = "Introduction"
sql.firstRow("select id from topic where name = ?", [name])

虽然这不是:

def sql = new Sql(dataSource)
def name = "Introduction"
sql.firstRow("select id from topic where name = ?", ["$name"])

它抛出错误 - org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of org.codehaus.groovy.runtime.GStringImpl. Use setObject() with an explicit Types value to specify the type to use.

这应该有效:

sql.firstRow("select id from topic where name = ?", ["$name".toString()])