2010-02-25 6 views
1

exécutant le code suivant:utilisant le type d'horodatage avec pg_prepare

$preCallMatch = pg_prepare($dbcp, 'callMatch', 
          "SELECT duration 
           FROM voip_calls 
           WHERE system_id = $1 
           AND call_start => $2         
           AND call_start <= $3 
           AND destination = $4"); 

Je reçois l'erreur suivante:

Warning: pg_prepare(): Query failed: ERROR: operator does not exist: timestamp without time zone => "unknown" 
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts. in /home/www/dinesh/UPSReconcileZeroSecondCalls.php on line 38 

J'ai essayé coulée 2 $ de cette manière sans chance:

$preCallMatch = pg_prepare($dbcp, 'callMatch', 
          "SELECT duration 
           FROM voip_calls 
           WHERE system_id = $1 
           AND call_start => CAST ($2 AS TIMESTAMP) 
           AND call_start <= CAST ($3 AS TIMESTAMP) 
           AND destination = $4"); 


Warning: pg_prepare(): Query failed: ERROR: operator does not exist: timestamp without time zone => timestamp without time zone 
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts. in /home/www/dinesh/UPSReconcileZeroSecondCalls.php on line 38 

Types de colonnes de la table voip_calls:

call_start  | timestamp without time zone | 
call_end  | timestamp without time zone | not null 

Des conseils sur ce que je fais mal? Remarque, PDO ou MDPD ne sont pas une option pour le moment.

versions du logiciel:

ii php5       5.2.6.dfsg.1-1+lenny3  server-side, HTML-embedded scripting languag 
ii libapache2-mod-php5    5.2.6.dfsg.1-1+lenny3  server-side, HTML-embedded scripting languag 
ii php5-pgsql      5.2.6.dfsg.1-1+lenny3  PostgreSQL module for php5 
ii libpq5       8.3.8-0lenny1    PostgreSQL C client library 
postmaster (PostgreSQL) 8.1.4 

Répondre

0

Il peut être votre opérateur => l'origine du problème - essayer> = à la place.

aussi comme un indice je trouve plus facile d'écrire timestamp 2 :: $ au lieu de CAST (2 $ TIMESTAMP) - il est une syntaxe spécifique à PostgreSQL mais pour me lit mieux (et il est moins à taper ;-))

+0

Oui, vous avez raison. La typo d'opérateur frappe à nouveau. – dinesh

0

Il s'avère que c'était les opérateurs < = et =>. Cela fonctionne bien:

$preCallMatch = pg_prepare($dbcp, 'callMatch', 
          "SELECT duration 
           FROM voip_calls 
           WHERE system_id = $1 
           AND call_start BETWEEN $2 AND $3 
           AND destination = $4");