From 110cc26b4dc7059b24312591e573b030371a8294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Konvi=C4=8Dka?= Date: Fri, 24 Oct 2025 17:46:00 +0200 Subject: [PATCH] add PostgreSQL-specific CAST support for text filters --- .../PostgreQueryObjectInterface.php | 10 ++++++++ src/QueryObject/QueryObject.php | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/QueryObject/PostgreQueryObjectInterface.php diff --git a/src/QueryObject/PostgreQueryObjectInterface.php b/src/QueryObject/PostgreQueryObjectInterface.php new file mode 100644 index 0000000..de93ab9 --- /dev/null +++ b/src/QueryObject/PostgreQueryObjectInterface.php @@ -0,0 +1,10 @@ +addColumnPrefix($_column); $_column = $this->getJoinedEntityColumnName($_column); + if ($this instanceof PostgreQueryObjectInterface && $this->hasDqlStringFunction('CAST')) { + switch ($mode) { + case QueryObjectByMode::EQUALS: + case QueryObjectByMode::NOT_EQUALS: + case QueryObjectByMode::STARTS_WITH: + case QueryObjectByMode::ENDS_WITH: + case QueryObjectByMode::CONTAINS: + case QueryObjectByMode::NOT_CONTAINS: + case QueryObjectByMode::IS_NULL: + case QueryObjectByMode::IS_NOT_NULL: + case QueryObjectByMode::IN_ARRAY: + case QueryObjectByMode::NOT_IN_ARRAY: + $_column = sprintf('CAST(%s AS TEXT)', $_column); + break; + } + } + switch ($mode) { case QueryObjectByMode::EQUALS: $condition = "$_column = :$paramName"; @@ -981,4 +999,11 @@ final public function addPostFetch(string $fieldName): static $this->postFetch[] = $fieldName; return $this; } + + protected function hasDqlStringFunction(string $name): bool + { + $config = $this->em->getConfiguration(); + + return (bool)$config->getCustomStringFunction($name); + } }