将时间戳类型与 pg_prepare 一起使用

发布于 2024-08-22 17:18:51 字数 2194 浏览 7 评论 0原文

运行以下代码:

$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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

自我难过 2024-08-29 17:18:52

可能是你的 =>导致问题的运算符 - 尝试使用 >= 代替。

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

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

如梦亦如幻 2024-08-29 17:18:52

原来是 <= 和 =>运营商。这样做效果很好:

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

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");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文