【发布时间】: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