Hi Benjamin,

thanks for that workaround. This works with minor modification (change 1 to 
TRUE):
SELECT f FROM Foo f WHERE AT_LOWER(f.jsonField, "something") = TRUE

Here is the Code for anybody that is interested:

class JsonbContains extends FunctionNode
{
    public $identifier = null;
    public $value = null;

    public function parse(\Doctrine\ORM\Query\Parser $parser)
    {
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->identifier = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_NONE);
        $parser->match(Lexer::T_GREATER_THAN);
        $this->value = $parser->ArithmeticPrimary();
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }

    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
    {
        return '(' .
        $this->identifier->dispatch($sqlWalker) . ' @> ' .
        $this->value->dispatch($sqlWalker) .
        ')';
    }
}


SELECT p
FROM AppBundle:Project p
WHERE JSONB_CONTAINS( p.values @> '{\"ACTIVE\": \"1\"}' ) = TRUE


Best,
Robin

On Monday, April 13, 2015 at 2:47:38 PM UTC+2, kontakt wrote:
>
> Hi Robin,
>
> that is not possible, the Parser is not extendable.
>
> You can however add a DQL function that translates to this by performing 
> some trickery: SELECT f FROM Foo f WHERE AT_LOWER(f.jsonField, "something") 
> = 1
>
> Then have AT_LOWER generate sql: (f.json_field @> "something") = 1 if that 
> is valid
>
> greetings
>
> On Mon, Apr 13, 2015 at 2:33 PM, Robin <[email protected] <javascript:>> 
> wrote:
>
>> I want to extend the Doctrine Parser: Doctrine\ORM\Query\Parser. In 
>> detail I want to add a ComparisonOperator (@> for postgresql jsonb) that 
>> I need for a custom Query.
>>
>> Is this possible without changing the File? When I change the Parser 
>> directly everything works fine, however I think that is not the way to go.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "doctrine-user" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/doctrine-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to