Storing milliseconds

732 views
Skip to first unread message

jeffhg58

unread,
Mar 27, 2007, 1:58:08 PM3/27/07
to Django users
I am using a postgresql database and was wondering if anyone knew how
to store milliseconds
in the database. I am using a datetime field and when I insert the
record the milliseconds is being truncated.

Thanks,
Jeff

Jonas Maurus

unread,
Mar 27, 2007, 4:10:47 PM3/27/07
to Django users

I find that strange, because Postgres doesn't natively support a
column-type "datetime". Nevertheless, you can use a timestamp column
for millisecond resolution

http://www.postgresql.org/docs/8.2/interactive/datatype-datetime.html

hope this helps,
Jonas

Jeremy Dunck

unread,
Mar 27, 2007, 5:37:45 PM3/27/07
to django...@googlegroups.com
On 3/27/07, Jonas Maurus <jonas....@gmail.com> wrote:
>
> On Mar 27, 7:58 pm, "jeffhg58" <jeffh...@comcast.net> wrote:
..

> > in the database. I am using a datetime field and when I insert the
> > record the milliseconds is being truncated.
>
> I find that strange, because Postgres doesn't natively support a
> column-type "datetime". Nevertheless, you can use a timestamp column
> for millisecond resolution

He means Django's DateTimeField.

Django creates a column of type 'timestamp with time zone' for
DateTimeField. The postgres docs claim microsecond resolution for
both with and without timezone.

Can you share some code demonstrating the trouble?

jeff...@comcast.net

unread,
Mar 28, 2007, 11:17:16 AM3/28/07
to django...@googlegroups.com
Basically, I  have django create the table and the snippet from models.py is:
 
ExecutionStartDate = models.DateTimeField(verbose_name = "Start Date")
 
And, then I have python load script which is loading the data with simple insert statements:
 
The data in the input file is
created = 22 Nov 2006 13:43:24.43
 
Through my django scripts it is truncating the .43.
 
I would assume that if milliseconds is supported that I would have to specify it in my models.py definitions.
 
Thanks,
Jeff
 
-------------- Original message --------------
From: "Jeremy Dunck" <jdu...@gmail.com>

>
> On 3/27/07, Jonas Maurus wrote:
> >
> > On Mar 27, 7:58 pm, "jeffhg58" wrote:
> ..
> > > in the database. I am using a datetime field and when I insert the
> > > record the milliseconds is being truncated.
> >
> > I find that strange, because Postgres doesn't natively support a
> > column-type "datetime". Nevertheless, you can use a timestamp column
> > for millisecond resolution
>
> He means Django's DateTimeField.
>
> Django creates a column of type 'timestamp with time zone' for
> DateTimeField. The postgres docs claim microsecond resolution for
> both with and without timezone.
>
> C an you share some code demonstrating the trouble?
>
>

Jeremy Dunck

unread,
Mar 28, 2007, 1:13:26 PM3/28/07
to django...@googlegroups.com
On 3/28/07, jeff...@comcast.net <jeff...@comcast.net> wrote:
>
> Basically, I have django create the table and the snippet from models.py
> is:
>
> ExecutionStartDate = models.DateTimeField(verbose_name = "Start Date")
>
> And, then I have python load script which is loading the data with simple
> insert statements:
>
> The data in the input file is
> created = 22 Nov 2006 13:43:24.43

Err, yeah, that's the bit I was asking for.

So, this doesn't work?
import datetime
from yourproject.yourapp import models

d = datetime.datetime(2006, 11, 22, 13, 43, 24, 43)
ex = models.Example(ExecutionStartDate=d)
ex.save()

?

It just worked for me, using pg 8.1 and django trunk.

Reply all
Reply to author
Forward
0 new messages