5
擁有的形式從PostgreSQL的時間戳中提取日期的最有效方法是什麼?
select * from foo
where created_on::date = '2014/1/1'
或
select * from foo
where date_trunc('day', created_on) = '2014/1/1'
或
select * from foo
where date(created_on) = '2014/1/1'
在什麼條件下不同的查詢執行得更好/更糟糕的查詢?哪三種選擇最有效?
你需要看執行計劃可以肯定的,但總的來講,在這樣一個功能包裝的表列你的第二個和第三個例子將防止任何索引使用,這會使你進行表掃描。 – Brandon
第四種可能性(待測試)是'select * from foo where created_on'2014/1/1 00:00:00'和'2014/1/2 00:00:00'' – Brandon
@Brandon:第一個表達式也會阻止索引的使用。 –