Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put infinity and minus infinity in Django FloatField?

I am trying to put infinity in a FloatField, but that doesn't seem to work. How do I solve this?

f = DjangoModel(float_value=float('inf')) #ok
f.save() #crashes

Results in:

Traceback (most recent call last):
...
ProgrammingError: column "inf" does not exist
LINE 1: ... "float_value") VALUES (inf)

I'm using Django 1.0.2 with PostgreSQL 8.3

like image 245
Jack Ha Avatar asked Jul 13 '09 13:07

Jack Ha


1 Answers

It seems like Djangos ORM doesn't have any special handling for this. Pythons representaton of the values are inf and -inf, while PostgrSQL wants 'Infinity' and '-Infinity'. Obviously Djangos ORM doesn't handle that conversion.

So you need to fix the ORM, I guess. And then think about the fact that other SQL databases may very well want other formats, or won't handle infinities at all.

like image 67
Lennart Regebro Avatar answered Nov 17 '22 20:11

Lennart Regebro