Opened 4 years ago

Closed 4 years ago

#32118 closed New feature (wontfix)

Add field for 4-bytes floats (RealField/SmallFloatField).

Reported by: Michael Owned by: nobody
Component: Database layer (models, ORM) Version: 3.1
Severity: Normal Keywords: Fields
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Michael)

In the DB world the difference between float (4 bytes) and double (8 bytes) is arguably common. However Django calls a double a float. I would imagine it would be very hard to add a DoubleField and make FloatField the normal 4 byte float due to legacy. Although not ideal how about adding a SmallFloatField, or RealField, or some other name to allow users to create a 4 byte floats, or raise awareness to when they use a FloarField, it may not be what they expect?

PostgresQL calls 4 byte float a real, and a 8 byte float a double precision:
https://www.postgresql.org/docs/9.1/datatype-numeric.html

Mysql calls 4 byte float a float, and a 8 byte float a double:
https://dev.mysql.com/doc/refman/8.0/en/floating-point-types.html

Note: People cite "space is cheap", but this is not always the case, and depending on the situation there are real practical savings.

Change History (2)

comment:1 by Michael, 4 years ago

Description: modified (diff)

in reply to:  description comment:2 by Mariusz Felisiak, 4 years ago

Resolution: wontfix
Status: newclosed
Summary: db.models.FloatField name misleadingAdd field for 4-bytes floats (RealField/SmallFloatField).

Replying to mangelozzi:

In the DB world the difference between float (4 bytes) and double (8 bytes) is arguably common. However Django calls a double a float.

Float in the field name refers to the way it's stored in Python, i.e. as a float, not to db data types. Also, as far as I'm aware, names of data types are not consistent across databases.

I would imagine it would be very hard to add a DoubleField and make FloatField the normal 4 byte float due to legacy. Although not ideal how about adding a SmallFloatField, or RealField, or some other name to allow users to create a 4 byte floats, or raise awareness to when they use a FloarField, it may not be what they expect?

I don't think we should add (and maintain) more field types. Moreover, you should be able to create your own subclass of FloatField by changing only db_type, e.g.

class RealField(FloatField):
    def db_type(self, connection):
        return 'real'

You can start a discussion on DevelopersMailingList if you don't agree.

Note: See TracTickets for help on using tickets.
Back to Top