Re: database not accepting data properly

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Shaan Repswal <shaun(dot)reapswaal(at)gmail(dot)com>, psycopg(at)postgresql(dot)org
Subject: Re: database not accepting data properly
Date: 2016-02-22 21:58:58
Message-ID: 56CB84A2.3060608@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

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(at)test=# \d sessionlogs
Table "public.sessionlogs"
Column | Type | Modifiers
-----------------+------------------------+-----------
sessiondate | date |
sessiontime | time without time zone |
sessionduration | interval(0) |
sessiondesc | text |

aklaver(at)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(at)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(dot)klaver(at)aklaver(dot)com

In response to

Browse psycopg by date

  From Date Subject
Next Message Frank Millman 2016-02-28 07:53:31 Problem with psycopg2 and asyncio
Previous Message Adrian Klaver 2016-02-22 15:41:32 Re: database not accepting data properly