ViszinisA
ViszinisA

Reputation: 462

How do I use CONCAT_WS together with IN?

Using Symfony2 and Doctrine2, want to combine CONCAT_WS with IN, rather than write a lot of IF's.

WHERE CONCAT_WS('-', id2, id2) IN ($ids)

I am receiving this error:

[Syntax Error] line 0, col 446: Error: Expected Doctrine\\ORM\\Query\\Lexer::T_IN, got '('

$ids are in form of '123-456'.

If I simply use a column instead of CONCAT_WS, it works:

WHERE id2 IN ($ids)

Upvotes: 3

Views: 3516

Answers (2)

Rorchackh
Rorchackh

Reputation: 2181

I've had the same problem as this, I solved it using this:

CONCAT(CONCAT('-', id2), id2)

Not the most elegant solution but it works. Writing a custom function is the way to go.

Upvotes: 0

P. R. Ribeiro
P. R. Ribeiro

Reputation: 3029

Not all MySQL functions are available for use in Doctrine. Only those functions that are common to all databases supported are available.

Follow this link to see the list of functions available by default http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#functions-operators-aggregates .

If you want to use CONCAT_WS anyway, read about creating custom functions on the following links. You can create your own DQL Custom Function and will be able to use just like you tried before.

http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/dql-user-defined-functions.html

http://symfony.com/doc/current/cookbook/doctrine/custom_dql_functions.html

Upvotes: 3

Related Questions