views:

108

answers:

2

Running the following code:

$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");

I get the following error:

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

I have tried casting $2 in this manner with no luck:

$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

Column types from voip_calls table:

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

Any tips as to what I'm doing wrong? Note, PDO or MDPD aren't an option right now.

Versions of software:

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
A: 

It may be your => operator causing the problem - try >= instead.

Also as a hint I find it easier to write $2::timestamp instead of CAST($2 AS TIMESTAMP) - it is a PostgreSQL-specific syntax but for me reads better (and it's less to type ;-) )

Andy Shellam
Yep, you're right. Operator typo strikes again.
dinesh
A: 

Turns out it was the <= and => operators. Doing this works fine:

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