problem with datetime prior to 1960
"Christian Ledermann" <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Python 2.5.1
Postgres 8.3.0
timezone = 'Africa/Nairobi' (it may not be reproduceable with other
timezones)
the row date_of_birth is implemented as timestamp with timezone.
>>> import psycopg2
>>> psycopg2.__version__
'2.0.6 (dec dt ext pq3)'
>>> dbcon = psycopg2.connect('dbname=mydb')
>>> dbcur = dbcon.cursor()
>>> dbcur.execute("SELECT * FROM users WHERE user_id=1")
>>> dbcur.fetchall()
[(1, None, 'Mr.', 'Jimmy', 'Buru', 'Arengah', 'Lagos', 'M',
datetime.datetime(2041, 12, 18, 0, 0, tzinfo=<
psycopg2.tz.FixedOffsetTimezone object at 0xb7a0b0cc>), 'KE', None, 'ID
xyzz', None, None, 'A', 'memberofparliament')]
>>>
PLSQL:
bungeni=# update users set date_of_birth='1960-12-18' where user_id=1;
UPDATE 1
bungeni=# select * from users where user_id=1
;
user_id | login | titles | first_name | last_name | middle_name |
email | gender | date_of_birth | birth_country | date_of_death
| national_id | password | salt | active_p | type
---------+-------+--------+------------+-----------+-------------+----------------+--------+------------------------+---------------+---------------+-------------+----------+------+----------+--------------------
1 | | Mr. | Jimmy | Buru | Arengah |
[email protected] | M | 1960-12-18 00:00:00+03 | KE
| | ID xyzz | | | A |
memberofparliament
(1 row)
PYTHON:
>>> dbcur.execute("SELECT * FROM users where user_id=1")
>>> print dbcur.fetchall()
[(1, None, 'Mr.', 'Jimmy', 'Buru', 'Arengah', '[email protected]', 'M',
datetime.datetime(1960, 12, 18, 0, 0, tzinfo=<
psycopg2.tz.FixedOffsetTimezone object at 0xb7c9226c>), 'KE', None, 'ID
xyzz', None, None, 'A', 'memberofparliament')]
PSQL:
bungeni=# update users set date_of_birth='1959-12-18' where user_id=1;
UPDATE 1
bungeni=# select * from users where user_id=1
;
user_id | login | titles | first_name | last_name | middle_name |
email | gender | date_of_birth | birth_country |
date_of_death | national_id | password | salt | active_p |
type
---------+-------+--------+------------+-----------+-------------+----------------+--------+------------------------------+---------------+---------------+-------------+----------+------+----------+--------------------
1 | | Mr. | Jimmy | Buru | Arengah |
[email protected] | M | 1959-12-18 00:00:00+02:44:45 | KE
| | ID xyzz | | | A |
memberofparliament
(1 row)
PYTHON:
>>> dbcur.execute("SELECT * FROM users where user_id=1")
>>> print dbcur.fetchall()
[(1, None, 'Mr.', 'Jimmy', 'Buru', 'Arengah', '[email protected]', 'M',
datetime.datetime(1959, 12, 18, 0, 0), 'KE', None, 'ID xyzz', None, None,
'A', 'memberofparliament')]
>>>
Traceback (most recent call last):
File "bin/python", line 153, in <module>
code.interact(banner="", local=globals())
File "/home/undesa/devel//lib/python2.5/code.py", line 302, in interact
console.interact(banner)
File "/home/undesa/devel//lib/python2.5/code.py", line 239, in interact
more = self.push(line)
File "/home/undesa/devel//lib/python2.5/code.py", line 261, in push
more = self.runsource(source, self.filename)
File "/home/undesa/devel//lib/python2.5/code.py", line 76, in runsource
code = self.compile(source, filename, symbol)
File "/home/undesa/devel//lib/python2.5/codeop.py", line 168, in __call__
return _maybe_compile(self.compiler, source, filename, symbol)
File "/home/undesa/devel//lib/python2.5/codeop.py", line 70, in
_maybe_compile
for line in source.split("\n"):
psycopg2.DataError: unable to parse time
Note that the fetchall() does not raise the error immediatly but rather the
next statement (here an empty cr)
any pointers?
thx
christian
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg