martin-georgiev / postgresql-for-doctrine

PostgreSQL enhancements for Doctrine. Provides support for advanced data types (json, jssnb, arrays), text search, array operators and jsonb specific functions.
https://packagist.org/packages/martin-georgiev/postgresql-for-doctrine
MIT License
357 stars 42 forks source link

`ANY` should accept `text[]` field, currently throw a `Expected Doctrine\ORM\Query\Lexer::T_SELECT` #138

Open allan-simon opened 1 year ago

allan-simon commented 1 year ago

i.e if I have a field featureFlags which is declared as text[]

and I try to do

       $this->em->createQuery("

            SELECT u FROM App\Entity\EndUser u
            WHERE 'something' = ANY(u.featureFlags)
        ");

I got Expected Doctrine\ORM\Query\Lexer::T_SELECT, got 'u'

whereas if i type directly in postgresql

SELECT * FROM end_users WHERE 'something' = ANY (feature_flags)

it works

TomLorenzi commented 1 year ago

As I'm working with my own DQL, the best solution for that would be to change the name of the called function. Doctrine only expect sub select as parameters, so it will trigger your error. Renaming ANY() to CUSTOM_ANY() as an example would allow you in your request to have something like this SELECT * FROM end_users WHERE 'something' = CUSTOM_ANY(feature_flags);

This will bypass the doctrine verification of ANY parameters and work

EDIT: looking at the docs, you should use ANY_OF() here, and it will do what I said above. @allan-simon

klobastov commented 1 year ago

same deprecatino for MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Cast