【问题标题】:two similar pg_query statements, one is OK, the other FAILS. Why?两个类似的 pg_query 语句,一个是 OK,另一个 FAILS。为什么?
【发布时间】:2014-01-17 16:06:55
【问题描述】:

我对正在发生的事情感到困惑。所以我只需要一些想法或说明。

我有 3 个 PHP 变量和两个 PostgreSQL 查询:

$date_start = $d1 = "2013-01-01";
$date_end = $d2 = "2013-01-05";
$car = "x";

$query_1 = pg_query($con, "SELECT AVG(longitude) as lon, AVG(latitude) as lat, MAX(longitude) as maxlon, MIN(longitude) as minlon, MAX(latitude) as maxlat, MIN(latitude) as minlat FROM table WHERE car='".$car."' AND testdate>='".$date_start."' AND testdate<='".$date_end."'";

$query_2 = pg_query($con, "SELECT MIN(testtime) as t1, MAX(testtime) as t2 FROM table WHERE car='$car' AND testdate>='$d1' AND testdate=<'$d2' GROUP BY testdate");

这里的问题是 $query_1 可以正常通过并给我一个正确的结果资源,而另一个总是 false 并显示错误消息:

ERROR: operator does not exist: date =< unknown
LINE 1: ... car='BM1' AND testdate>='2013-04-04' AND testdate=<'2013-04...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

那么...有什么想法吗?我确信查询几乎相同,但由于我不明白 PostgreSQL 抱怨一个而不是另一个的原因!

我确实需要有关如何解决此问题的帮助,我只需要知道原因。为什么行为不同..

干杯!!

你的 安迪

【问题讨论】:

    标签: sql postgresql date where-clause


    【解决方案1】:

    我不是 postgress 专家,但 AFAIK 没有 = 运算符,但

    $query_2 = pg_query($con, "SELECT MIN(testtime) as t1, MAX(testtime) as t2 FROM table WHERE car='$car' AND testdate>='$d1' AND testdate=<'$d2' GROUP BY testdate");
    

    【讨论】:

    • 确实!一个我看不到的小错字!谢谢你! :)
    猜你喜欢
    • 2018-12-18
    • 2023-03-21
    • 2016-08-18
    • 1970-01-01
    • 2013-10-27
    • 2018-01-21
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    相关资源
    最近更新 更多