Re: Performance for django for years
Thanks. Now, I will use PositiveSmallIntegerField I don't need a whole PositiveIntegerField (1900-->2100) and I want to compare years Thanks a lot, Xan. PS: Greg, yes there are lot of documentation, but it's more technical. Web site of django offers a good tutorial, good for "anybody". Rails offers information for gurus or developers at least. On Sep 9, 9:22 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > > Well, secondly I have one question: I have a model A that have a field > > "year" that means the year that A was made. I just want to know if > > it's best (for performance) to code as: > > > class A(models.Model): > > year = models.CharField(maxlength=4) > > [...] > > > or > > class A(models.Model): > > year = models.PossitiveIntegerField() > > [...] > > > what it's the best for database performance (I use mysql) > > I don't think has considerable performances reasons to choose one > over the other. However, for sorting and validation purposes, > you might want to go with the PositiveIntegerField (one "s" in > "Positive"). > > For sorting purposes, an integer field may be a tiny portion > faster than the char field. > > You might even slap on some validators if your years don't extend > too far back. It's one thing if you're using years for dating > early Judeo-Christian literature, where you might have valid > years such as "214". However, if all your years are recent-ish, > you can toss a validator on your field to ensure, say, that the > value is since 1900 or some other such limitation. > > I would lean towards validated PositiveIntegerField fields. > > -tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Performance for django for years
On Sun, 9 Sep 2007, Xan wrote: > Well, first of all, thank you for django. I'm not programmer and I > just wanted to code some web app easier as I can do. I tried rails but > there is no free documentation (almost all doc are books and books) I wasn't charged anything before being allowed to access any of these: http://railsmanual.org/ http://api.rubyonrails.com/ http://wiki.rubyonrails.com/rails/pages/Howtos > and there is no have easy way for writing models. `script/generate model foo` seems very easy to me. > With django I found > the easier way for doing it. If you say so. I find the models in Django to be very lacking compared to Rails ActiveRecord models. > Well, secondly I have one question: I have a model A that have a field > "year" that means the year that A was made. I just want to know if > it's best (for performance) to code as: > > class A(models.Model): > year = models.CharField(maxlength=4) > [...] > > or > class A(models.Model): > year = models.PossitiveIntegerField() > [...] > > what it's the best for database performance (I use mysql) For performance an unsigned smallint beats a varchar(4) any day of the week. -- Greg Donald Cyberfusion Consulting http://cyberfusionconsulting.com/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Performance for django for years
> Well, secondly I have one question: I have a model A that have a field > "year" that means the year that A was made. I just want to know if > it's best (for performance) to code as: > > class A(models.Model): > year = models.CharField(maxlength=4) > [...] > > or > class A(models.Model): > year = models.PossitiveIntegerField() > [...] > > what it's the best for database performance (I use mysql) I don't think has considerable performances reasons to choose one over the other. However, for sorting and validation purposes, you might want to go with the PositiveIntegerField (one "s" in "Positive"). For sorting purposes, an integer field may be a tiny portion faster than the char field. You might even slap on some validators if your years don't extend too far back. It's one thing if you're using years for dating early Judeo-Christian literature, where you might have valid years such as "214". However, if all your years are recent-ish, you can toss a validator on your field to ensure, say, that the value is since 1900 or some other such limitation. I would lean towards validated PositiveIntegerField fields. -tim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---