2

In my OrientDB instance, entries have date property which is stored as a java.util.Date.

I would like to get all documents written on a given year. But I don't think writing

SELECT FROM posts WHERE date.format('yyyy')=2012

Is the best way to do. or is it ?

Riduidel
  • 22,052
  • 14
  • 85
  • 185
  • Well I think for those things, especially years, it's way better to use clustering. – kwoxer Oct 30 '14 at 13:01
  • possible duplicate of [How do I query for all dates greater than a certain date in sql server?](http://stackoverflow.com/questions/10643379/how-do-i-query-for-all-dates-greater-than-a-certain-date-in-sql-server) – Riduidel Oct 30 '14 at 16:14
  • It can easily be rewritten as a date greater than or lower than using previously mentionned question, so I close mine. – Riduidel Oct 30 '14 at 16:15
  • Oh, no, inf act, it's a SQL question, and not an OrientDB one .... – Riduidel Oct 30 '14 at 16:16

1 Answers1

3

The given query is very inefficient, a full table scan will be performed. Best is to use (a possible index can be used):

select from posts where date between '2012-01-01 00:00:00' and '2012-12-31 23:59:59'

Assumption: date is of type Date(Time)

rmuller
  • 12,062
  • 4
  • 64
  • 92