database not accepting data properly

From: Shaan Repswal <shaun(dot)reapswaal(at)gmail(dot)com>
To: psycopg(at)postgresql(dot)org
Subject: database not accepting data properly
Date: 2016-02-21 10:45:34
Message-ID: CALa+hEQwjuf_t=2tMfqF_wVA9VbiCC-25ohsttfB0yPtnb0-NA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

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).

here are the lines where the error probably is:-
print(cur.mogrify("""SELECT %s, %s, %s, %s""", (self.start_time.date(),
self.start_time.time(), datetime.datetime.now() - self.start_time,
desc_text)))
cur.execute("""INSERT INTO sessionlogs(sessiondate, sessiontime,
sessionduration, sessiondesc)
VALUES(%s, %s, %s, %s);""", (self.start_time.date(),
self.start_time.time(), datetime.datetime.now() - self.start_time,
desc_text))

although when I wrote another script to enter a specific code, it was
working just fine.

datetime.datetime.now() - self.start_time is the time interval which seems
to be where the error is.

when I did this :-
cur.execute("""INSERT INTO sessionlogs(sessiondate, sessiontime,
sessionduration, sessiondesc)
VALUES (%s, %s, %s, %s)""", (datetime.datetime.now().date(),
datetime.datetime.now().time(), datetime.timedelta(1, 18268), "This is a
manual entry"))

It was working quite fine.

I will attach the two scripts

Sorry for the uber messy code. I hope you can read through my whole script
as it isn't very big. I am using Gtk 3+ here so be warned... :P

Attachment Content-Type Size
testProductivityApp.py application/octet-stream 4.3 KB
manualaitestdbentry.py application/octet-stream 439 bytes

Responses

Browse psycopg by date

  From Date Subject
Next Message Adrian Klaver 2016-02-21 15:58:50 Re: database not accepting data properly
Previous Message Daniele Varrazzo 2016-02-20 13:25:56 Re: How to use "WHERE NOT EXISTS in INSERT STATEMENT"