-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
B.C./Negative Year Dates #166
Comments
It turns out that Python's datetime module only supports AD dates. See here and note the description of MINYEAR which is 1. If you subtract 4712 from 65536 you get 60824. I'll add some code to cx_Oracle to raise an exception when an unsupported date is returned instead of simply returning a bogus date! |
Fair enough. Thank you. I suppose I could create a custom outputtypehandler to potentially handle B.C. dates in a custom manner? |
You're welcome. And yes, you could use an output type handler to return the date as a string and then do something custom with it. |
… like Python 3.x does (#166).
I just checked with Python 3.6 and it raises the exception: ValueError: year -4712 is out of range. I've just added code that does the same for Python 2.7. |
Hi I am facing the same issue, i created output type handler to convert the negative timestamp to string but it is still not returning - year, instead it it returning the year without minus sign, could you help how to get whether the year is negative or not using output type handler i am returning this from type handler |
@iamshubh95 show the SQL to create the table column, data in the table and a runnable python testcase. Thanks. |
@cjbj then i created output type handler for changing this timestamp to string using the code i already have written it isnt giving back the year with minus |
The TIMESTAMP doc doesn't show a leading "-" is allowed for timestamps. Also, SQL*Plus returns the date you see with a type handler.
so this doesn't seem a cx_Oracle issue. Intervals seem OK. In Python 3, a query:
prints
|
As written in doc you shared Returns the year for the given timestamp. The returned value is in the range -6383 to 9999. If the argument is NULL or empty, the result is also NULL or empty. year can take any value between -6383 to 9999. Also when using this query My issue is i cant use extract as i dont have control over the sql used. |
just to make my problem more clear and then use this type handler- |
If I fetch from SQL*Plus I see the following data (based on your inserts):
And that is the data you get from cx_Oracle as well. So this is not a cx_Oracle issue. You'll need to contact Oracle support regarding this! |
Thanks @anthony-tuininga i will ask this issue with oracle support. |
What version of cx_Oracle are you using? With Python 3.7 and cx_Oracle 7.1 I get the error "ValueError: year -1 is out of range". |
python - 2.7.11 |
Just a update, |
Glad to hear you found a solution. Please note that Python does not support negative years: https://docs.python.org/3/library/datetime.html. There was a bug in previous versions (aka Python 2.x) that didn't check -- but it was a bug, not a feature. :-) |
I am getting an unexpected response when extracting B.C. dates and think it might be some sort of arithmetic overflow error (potentially, speculating a bit)...
Below is the queries run in SQL Developer and what is being returned (in Python). Obviously, the main concern is the year coming back as 60824
SQL Developer Queries
Python object returned in fetch()/fetchmany()
datetime.datetime(60824, 1, 1, 0, 0)).
The text was updated successfully, but these errors were encountered: