On 02/21/2016 02:45 AM, Shaan Repswal wrote:
> Hey guys, I hope I used the Mailing List properly. I am trying to upload
> a datetime.timedelta object into a column of type interval... But when I
> query it says datetime.interval(0).
>
Had some time to run the attached code. Other then making a change to
the database in connect() and adding some print functions it is the
same. Running the application I got an interval in the sessionduration
field. Details below:
postgres@test=# \d sessionlogs
Table "public.sessionlogs"
Column | Type | Modifiers
-----------------+------------------------+-----------
sessiondate | date |
sessiontime | time without time zone |
sessionduration | interval(0) |
sessiondesc | text |
aklaver@killi:~> python testProductivityApp.py
('First', <type 'datetime.datetime'>)
('Second', datetime.datetime(2016, 2, 22, 13, 38, 34, 870868))
SELECT '2016-02-22'::date, '13:38:34.870868'::time, '0 days 4.497017
seconds'::interval, 'Enter here how you utilised your time.'
('Second', datetime.datetime(2016, 2, 22, 13, 38, 42, 440964))
SELECT '2016-02-22'::date, '13:38:42.440964'::time, '0 days 184.828224
seconds'::interval, 'Enter here how you utilised your time.'
('Second', datetime.datetime(2016, 2, 22, 13, 41, 50, 29445))
SELECT '2016-02-22'::date, '13:41:50.029445'::time, '0 days 568.953356
seconds'::interval, 'Enter here how you utilised your time.'
('Second', datetime.datetime(2016, 2, 22, 13, 51, 51, 293405))
SELECT '2016-02-22'::date, '13:51:51.293405'::time, '0 days 0.611630
seconds'::interval, 'Enter here how you utilised your time.'
('Second', datetime.datetime(2016, 2, 22, 13, 52, 17, 473494))
SELECT '2016-02-22'::date, '13:52:17.473494'::time, '0 days 0.417363
seconds'::interval, 'Enter here how you utilised your time.
postgres@test=# select * from sessionlogs ;
sessiondate | sessiontime | sessionduration |
sessiondesc
-------------+-----------------+-----------------+----------------------------------------
2016-02-22 | 13:38:34.870868 | 00:00:04 | Enter here how you
utilised your time.
2016-02-22 | 13:38:42.440964 | 00:03:05 | Enter here how you
utilised your time.
2016-02-22 | 13:41:50.029445 | 00:09:29 | Enter here how you
utilised your time.
2016-02-22 | 13:51:51.293405 | 00:00:01 | Enter here how you
utilised your time.
2016-02-22 | 13:52:17.473494 | 00:00:00 | Enter here how you
utilised your time.
(5 rows)
The only way I could get only 0's was to have a duration less then 0.5
seconds. So the code works here.
--
Adrian Klaver
adrian.klaver@aklaver.com