繁体   English   中英

在pg_prepare中使用时间戳类型

[英]Using timestamp type with 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");

我收到以下错误:

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

我试过以这种方式投放$ 2,但没有运气:

$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

voip_calls表中的列类型:

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

关于我在做什么错的任何提示吗? 请注意,目前暂时无法选择PDO或MDPD。

软件版本:

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

可能是您的=>运算符引起了问题-请尝试> =。

同样作为提示,我发现编写$ 2 :: timestamp而不是CAST($ 2 AS TIMESTAMP)更容易-这是一种PostgreSQL特定的语法,但对我来说读起来更好(并且键入的次数更少;-))

原来是<=和=>运算符。 这样做工作正常:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM