"Impossible" phenomenon
The number of rows returned is completely independent of items in the SELECT
clause. (But see @Craig's comment about SRFs.) Something must be broken in your db.
Maybe a broken covering index? When you throw in the additional column, you force Postgres to visit the table itself. Try to re-index:
REINDEX TABLE my_db_log;
The manual on REINDEX
. Or:
VACUUM FULL ANALYZE my_db_log;
Better query
Either way, use instead:
select id from my_db_log
where creation_date >= '2014-03-05'::date
Or:
select id from my_db_log
where creation_date >= '2014-03-05 00:00'::timestamp
'2014-03-05'
is in ISO 8601 format. You can just cast this string literal to date
. No need for to_date()
, works with any locale. The date
is coerced to timestamp [without time zone]
automatically when compared to creation_date
(being timestamp [without time zone]
). More details about timestamps in Postgres here:
Ignoring timezones altogether in Rails and PostgreSQL
Also, you gain nothing by throwing in date_trunc()
here. On the contrary, your query will be slower and any plain index on the column cannot be used (potentially making this much slower)