|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-04-04 17:00 UTC] alan dot harder at sun dot com
Description:
------------
parameter given as integer but treated as text with particular sql syntax. remove "distinct" from the sql and it works.
Tested with PHP 5.1.2 and PHP 5.1.3-RC2
pg_version output:
array(3) { ["client"]=> string(5) "8.1.2" ["protocol"]=> int(3) ["server"]=> string(6) "7.4.11" }
Reproduce code:
---------------
First in psql:
create table test (val integer);
Test code:
<?php
$db = pg_connect('dbname=testdb');
if (!$db) return;
$s = pg_query_params($db, 'insert into test select distinct $1', array(666));
if ($s === false) {
print pg_last_error($db);
} else {
print "OK\n";
}
pg_close($db);
?>
Expected result:
----------------
OK
Actual result:
--------------
Warning: pg_query_params() [function.pg-query-params]: Query failed: ERROR: column "val" is of type integer but expression is of type text HINT: You will need to rewrite or cast the expression. in /usr/home/mindless/public_html/pgtest.php on line 5
ERROR: column "val" is of type integer but expression is of type text HINT: You will need to rewrite or cast the expression.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 12:00:01 2025 UTC |
for what it's worth, in my setup i only see the problem via PHP.. psql won't let me "prepare" without a type. maybe the problem is in the pg8 client library, setting a default type to text if you don't specify. array(3) { ["client"]=> string(5) "8.1.4" ["protocol"]=> int(3) ["server"]=> string(6) "7.4.13" } in psql: testdb=> prepare blah as insert into test select distinct $1; ERROR: there is no parameter $1 testdb=> prepare blah(int) as insert into test select distinct $1; PREPARE but via PHP, Warning: pg_query_params() [function.pg-query-params]: Query failed: ERROR: column "val" is of type integer but expression is of type text HINT: You will need to rewrite or cast the expression. adding ::int in the pg_query_params sql does work, as you suggested.