PHP Postgresql query results in malformed array literal with large array

34 views Asked by At

I'm trying to pass an array in a sql query using PHP.

Here's my php script :

$php_array = json_decode($_POST['id'], true);
$arr = '{'.implode(', ',$php_array).'}';  
$sql = "SELECT tableB.id, tableB.names, from tableA inner join tableB
on tableA.id like '%' || tableB.id || '%' where tableB.id = ANY($1)
GROUP BY tableB.id, tableB.names
ORDER BY tableB.names DESC;";
$result = pg_prepare($db, "query", $sql);
$query = pg_execute($db, "query", array($arr));

This query usually works. However, with my real dataset which includes around 29'000 ids (i.e. my array will have a lenght of 29'000) I end up with the following error message :

Warning: pg_execute(): Query failed: ERROR: malformed array literal: "{12345, 56789, 13579, ...}"
DETAIL: Unexpected "," character. CONTEXT: unnamed portal parameter $1 = '...'

I've check, and the array seems ok.

Do you have an idea what might be causing this issue ?

0

There are 0 answers