2014-01-17 29 views
0

我對發生的事情感到困惑。所以我只需要一些想法或澄清。兩個類似的pg_query語句,其中一個是OK,另一個是FAILS。爲什麼?

我有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獲得通過罰款,並給了我一個正確的結果資源,而另外一個總是帶着一個錯誤信息虛假:

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是在抱怨一個而不是另一個!

需要幫助就如何解決這個問題,我只需要知道原因。爲什麼行爲不同..

乾杯!

此致 安迪

回答

1

我不是一個postgress專家,但據我所知,沒有= <運營商,但< =

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

的確!一個我無法看到的小錯字!謝謝! :) – earthian

+0

:)用額外的眼睛總是很好 –

相關問題