0

This is the SQL I get from Django when making a date query on Oracle (i is an instance of Model.objects):

from datetime import datetime as dt
dates = [dt(2014,07,01), dt(2014,07,02)]
print i.filter(incd_date_d__range=dates).query

SELECT "SCHEMA"."TABLE"."COL1", "SCHEMA"."TABLE"."DATE_COL" 
FROM "SCHEMA"."TABLE" 
WHERE "SCHEMA"."TABLE"."DATE_COL" 
BETWEEN 2014-07-01 00:00:00 AND 2014-07-02 00:00:00

This returns a database error (ORA-01850: hour must be between 0 and 23). Notice how the dates are not surrounded by inverted commas. Is this intended behaviour?

dmvianna
  • 15,088
  • 18
  • 77
  • 106
  • I cannot replicate your error, what version of Oracle are you using? – Burhan Khalid Sep 29 '14 at 04:57
  • http://stackoverflow.com/questions/4668619/django-database-query-how-to-filter-objects-by-date-range Does this work for you? – kums Sep 29 '14 at 05:51
  • What type is `incd_date_d`? – Burhan Khalid Sep 29 '14 at 06:22
  • @BurhanKhalid `DateTimeField()`. – dmvianna Sep 29 '14 at 06:27
  • What's your database driver? – Burhan Khalid Sep 29 '14 at 06:31
  • @BurhanKhalid oracle-instantclient12.1-odbc-12.1.0.1.0-1.x86_64.rpm & unixODBC-2.2.14 – dmvianna Oct 01 '14 at 00:11
  • Its strange because I did the exact query and I don't get any errors, which makes me suspect the driver. For reference, you should not use the ODBC driver use the following: `oracle-instantclient12.1-basic-12.1.0.1.0-1.x86_64.rpm` and `oracle-instantclient12.1-devel-12.1.0.1.0-1.x86_64.rpm` from the Oracle [download site](http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html). – Burhan Khalid Oct 01 '14 at 04:32
  • @BurhanKhalid You may be right. However, SQLAlchemy works seamlessly with the current setup, and so does cx_Oracle. – dmvianna Oct 01 '14 at 05:37
  • 1
    I ran this query, with the same output as yours, and it did not give me an error from Oracle; so I don't think this has to do with inverted commas. – Burhan Khalid Oct 01 '14 at 05:47
  • Interesting, because it gives me an error when I run this query in Oracle SQL Developer running in a remote desktop. – dmvianna Oct 01 '14 at 06:16
  • @BurhanKhalid I actually have the drivers you suggested installed. – dmvianna Oct 03 '14 at 03:14

0 Answers0