I managed to simulate the error and get the same SQL state 42725
, by default the Standard uses emulated Prepared statements, what PDO driver does is to send all values as strings, so the error happens postgres expect integers in your query but strings are passed.
The error generated is:
ERROR: operator is not unique: Unknown - Unknown
SQL state: 42725
Hint: Could not choose an operator that fits better. You need to add explicit type conversions.
Feint of error
Example - sqlfiddle
To simulate the error just a very simple query,
To obtain the error without a prepared query, the test is done directly in pgAdmin or phpPgAdmin with this query or similiar(other operators)
SELECT '1'- '1'
PHP
<?php
$options = array(PDO::ATTR_EMULATE_PREPARES => false);
$db = new PDO('pgsql:host=localhost;dbname=postgres user=usuario password=senha', $options);
$sql = "SELECT ? + ?";
$stmt = $db->prepare($sql);
$stmt->execute(array(10,5));
$res = $stmt->fetch(PDO::FETCH_ASSOC);
echo '<pre>';
print_r($res);
Solution
Change the option PDO::ATTR_EMULATE_PREPARES
for true
, this setting is set in the class Illuminate\Database\Connectors\Connector
and PostgresConnector
inherits her. In the laravel5.1, open the folderslaravel\framework\src\illuminate\database\connectors
.
Original configuration:
protected $options = [
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
PDO::ATTR_EMULATE_PREPARES => false,
];
or cast (type) in placeholders, as below.
$sql = 'select ?::int - ?::int as resultado';
//teste do pgAdmin
SELECT '10'::int - '5'::int as resultado';
I suspect the error is here
".$destino." - ".$width."
both are ints?– rray
yes, all the variables
– Matheus Ilário
Could you echo this sql and ask the question? if you can put pg_query() of it tbm would be good.
– rray
When you copy and paste this query in pgAdmin appears any more description about the error? try so
".$destino."::int - ".$width."::int
– rray
The procedure of my reply worked for your case?
– rray