Postgresql SQLSTATE[42P18]: Indeterminate datatype with PDO and CONCAT
CONCAT
is a function that takes a VARIADIC argument list, which means that internally postgres will convert them into an array of the same type.
postgres=# \df concat List of functions Schema | Name | Result data type | Argument data types | Type ------------+--------+------------------+---------------------+------ pg_catalog | concat | text | VARIADIC "any" | func
When trying to resolve the input type to a single type, the SQL parser fails. It can be reproduced in this simpler form:
postgres=# PREPARE p AS select concat('A', $1);ERROR: could not determine data type of parameter $1
The parser can't figure out the datatype of $1
so it errs on the side of caution.
One easy solution is to cast the parameter as text:
postgres=# PREPARE p AS select concat($1::text);PREPARE
or with the CAST operator:
postgres=# PREPARE p AS select concat(cast($1 as text));PREPARE
I haven't tested with PDO but presumably it would work (given how it deals with parameters to produce prepared statements) to change the query to:
"...identification LIKE '%' || :identification || '::text%'..."
or use the '||' operator instead of concat
in the query:
identification LIKE '%' || :identification || '%'
EDIT: BTW if you want to find that a parameter :X
is a substring of identification
, this clause is more secure: strpos(identification, :X) > 0
, because :X
may contain '%' or '_' without causing any side-effect in the match, contrary to what happens with LIKE
.