Field type for 13 digit positive integer?

2,757 views
Skip to first unread message

coan

unread,
Sep 2, 2008, 3:35:09 PM9/2/08
to Django users
If I want to store a positive integer like 9781590599969 and use mysql
- what field type can I choose in my model - if any?

tchendrix

unread,
Sep 2, 2008, 3:36:58 PM9/2/08
to django...@googlegroups.com
that looks like it's for an EAN code... how are you planning on EAN14
and EAN 15?

coan

unread,
Sep 2, 2008, 3:40:58 PM9/2/08
to Django users
On Sep 2, 9:36 pm, tchendrix <tchend...@gmail.com> wrote:
> that looks like it's for an EAN code... how are you planning on EAN14
> and EAN 15?

I will take them on one digit at a time :-)
First I have to solve my 13 digit problem.

tchendrix

unread,
Sep 2, 2008, 3:50:20 PM9/2/08
to django...@googlegroups.com
the reason i'm asking is that digits 14 and 15 will be alphanumeric so add another field or two for that data (char?) and use bigint to hold the numerical data

coan

unread,
Sep 2, 2008, 4:00:06 PM9/2/08
to Django users

For now I was planning to store ISBN13 and 13 digit ean codes.

In mysql a bigint field would hold these, but I see no corresponing
fieldtypes in django for bigints -
the positiveintegerfield sets itself up as an int(10) signed field
type in mysql. -
I guess I could store them as charfields, but I think lookups go
faster in a bigintfield.

Larrik Jaerico

unread,
Sep 3, 2008, 2:11:22 PM9/3/08
to Django users
I was looking for some extremely large integers as well, so you aren't
alone. Though at the moment I can't remember what I needed them for.

Ross Dakin

unread,
Sep 3, 2008, 3:15:46 PM9/3/08
to Django users
I don't know about lookup speeds, but I believe the storage
requirement would be smaller if you go with a numeric data type over
characters:

To represent all 13-digit unsigned integers, you need 47 bits (2^47 =
1.4 * 10^14).

To represent a 13-character string (that may be composed of digits),
you need at least 104 bits (8 bytes * 13). You might need more than
one byte per character depending on your character encoding.

So it looks to me like storing numbers in numeric format requires
about half the space as character format in this case. Of course, you
can't store just 47 bits exactly in MySQL; you'll probably spend 64
bits of storage space (seems like the next logical boundary, haven't
checked the docs for specifics though). But even so, it cheaper than
storing numbers as characters.

And of course, this is probably a trivial matter unless you have huge
amounts of numbers to store.

julianb

unread,
Sep 3, 2008, 5:05:37 PM9/3/08
to Django users
On Sep 2, 10:00 pm, coan <a.ne...@gmail.com> wrote:
> For now I was planning to store ISBN13 and 13 digit ean codes.
>
> In mysql a bigint field would hold these, but I see no corresponing
> fieldtypes in django for bigints -
> the positiveintegerfield sets itself up as an int(10) signed field
> type in mysql. -

I use bigint(13) usigned in MySQL and positiveintegerfield in Django.
You have to change it manually in the db after the tables got created.

Ross Dakin

unread,
Sep 3, 2008, 5:17:56 PM9/3/08
to django...@googlegroups.com
BIGINT will store 64 bits.  The (13) display value has no baring on the data stored, but only how it is displayed.

http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
--
Ross Dakin
ross...@gmail.com
(858) 699-2190


CONFIDENTIALITY NOTICE: The contents of this message, together with any attachments, are intended only for the use of the persons and/or entities to which they are addressed and may contain confidential and/or privileged information that may be protected by legal privilege and/or is otherwise exempt from disclosure. If you are not the intended recipient of this message, please alert the sender immediately, destroy this message and any attachments, and be aware that any dissemination, disclosure, distribution, copying or use of the information contained in this e-mail, or any attachment, is strictly prohibited and governed by applicable law.
Reply all
Reply to author
Forward
0 new messages