【问题标题】:Can I create a custom criteria query like我可以创建一个自定义条件查询吗
【发布时间】:2018-04-19 17:30:57
【问题描述】:

我有一个旧的 PostgreSql 表,其中包含具有多个值的列。我想在我的搜索中选择包含任何值的行。

-- Example query
select * from stuff where ARRAY['Value A', 'Value X'] && regexp_split_to_array(thing, '\|');

我可以从 Grails 2.5.1 GORM 4.x 条件查询中生成这种类型的 where 条件吗?

仅供参考:我已经看到“Grails Postgresql 扩展插件”,但目前无法更改列定义。

【问题讨论】:

    标签: grails grails-orm


    【解决方案1】:

    您可以在条件中使用sqlRestriction 来添加任意SQL 条件。在bottom of the node reference for createCriteria() 中提到过。

    Stuff.withCriteria {
        sqlRestriction "ARRAY['Value A', 'Value X'] && regexp_split_to_array(thing, '\|')"
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      • 2013-02-07
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      相关资源
      最近更新 更多