gpt4 book ai didi

postgresql - Grails/Gorm 和 Postgresql Unaccent

转载 作者:行者123 更新时间:2023-11-29 13:31:11 25 4
gpt4 key购买 nike

我有一个关于如何在 Grails 中使用 PostgreSQL 的 unaccent 扩展的问题。

我有很多法语描述,而且 PostgreSQL 不区分重音。我安装了 unaccent 扩展,它在 PgAdmin III 上运行良好。

如何配置 Grails 和/或 PostgreSQL 以在我的 Controller 中使用 unaccent?

这是我的域名:

Class Description {
String content
int type = -1
}

例如,我可以使用 GORM“翻译”下一个查询吗?

SELECT content 
FROM description
WHERE unaccent(content) ILIKE unaccent(%myInputHere%)

感谢阅读

最佳答案

由于这是特定于 SQL 的,因此您需要使用 SQL Restriction在你的标准之内。例如:

def myinput = params.myinputfieldname
def results = Description.createCriteria().list() {
sqlRestriction "unaccent(content) ILIKE unaccent('%$myinput%')"
}

至少是这样。

编辑

请注意,上述限制中的“内容”指的是实际的 SQL 列名,而不是域的字段名。

关于postgresql - Grails/Gorm 和 Postgresql Unaccent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22763140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com