Symfony2 Doctrine – PostgreSQL的ILIKE子句?

Symfony2 Doctrine – PostgreSQL的ILIKE子句?,第1张

概述我目前正在使用symfony2,doctrine 2.3和PostgreSQL 9.我现在一直在寻找几个小时来看看我是如何使用QueryBuilder进行ILIKE选择的. 看起来他们只有喜欢.但在我的情况下,我正在搜索不区分大小写的内容. 怎么样呢? // -- this is the "like";$search = 'user';$query = $this->createQueryBu 我目前正在使用symfony2,doctrine 2.3和Postgresql 9.我现在一直在寻找几个小时来看看我是如何使用queryBuilder进行IliKE选择的.

看起来他们只有喜欢.但在我的情况下,我正在搜索不区分大小写的内容.
怎么样呢?

// -- this is the "like";$search = 'user';$query = $this->createqueryBuilder('users');$query->where($query->expr()->like('users.username',$query->expr()->literal('%:username%')))->setParameter(':username',$search);// -- this is where I get "[Syntax Error] line 0,col 86: Error: Expected =,<,<=,<>,>,>=,!=,got 'IliKE'$search = 'user';$query = $this->createqueryBuilder('users');$query->where('users.username IliKE :username')->setParameter(':username',$search);
我不知道Symphony,但你可以替代
a IliKE b

lower(a) liKE lower(b)

您也可以尝试运算符~~ *,这是IliKE的同义词
它的运算符优先级略低,因此您可能需要使用连续字符串的括号,而不是IliKE

a IliKE b || c

a ~~* (b || c)

The manual about pattern matching,starting with LIKE / ILIKE.

我认为这个人有同样的问题,并得到了答案:
http://forum.symfony-project.org/viewtopic.php?f=23&t=40424

显然,您可以使用sql供应商特定的功能扩展Symfony2:
http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/cookbook/dql-user-defined-functions.html

我不是ORM和框架的粉丝,只是为了保持“便携式”(几乎无法工作)而屠杀Postgres的丰富功能.

总结

以上是内存溢出为你收集整理的Symfony2 Doctrine – PostgreSQL的ILIKE子句?全部内容,希望文章能够帮你解决Symfony2 Doctrine – PostgreSQL的ILIKE子句?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/1181628.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-02
下一篇2022-06-02

发表评论

登录后才能评论

评论列表(0条)

    保存