Database column type 'decimal' ignored

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
Database column type 'decimal' ignored
« on October 7th, 2012, 02:02 AM »
In plugin-info.xml, if there is a column typed 'decimal', it is ignored. Since it is a valid type in MySQL, shouldn't it be added to the list of allowed database types?
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Database column type 'decimal' ignored
« Reply #1, on October 7th, 2012, 02:12 AM »
Who uses the bastardised format that is decimal? (Or, numeric, as it is also known)

I don't want to support it because I saw absolutely no good reason to extend everything in all the relevant places to extend a datatype that is not even consistent between MySQL versions, but if that weren't enough, it isn't even necessarily consistent between the same version of MySQL on different operating systems, and in some cases even between different table types on the same system.

If you are using it, the chances are you're really using the wrong data type and should be using something else.
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Database column type 'decimal' ignored
« Reply #5, on October 7th, 2012, 02:45 AM »
Ah, you clearly don't read TheDailyWTF, because you'd know the answer straight away ;) :P

There is one simple rule when dealing with data like this and it is in the form of a yes/no question. Do you ever need to do manipulation on it as if it is a number? If the answer to this question is yes, find a suitable numeric column. If the answer to this question is no, make it a string and be done with it.[1]

Just because something takes the form of a number does not inherently mean you should store it as one. Seems to me that you're really recording data from Google Maps that just happens to be in the form of a number, and that you don't need to perform any maths on it (e.g. distance location) in which case the correct type would be a string.

Making it a string has other advantages - you never have a loss of precision. What column size would you have used for example? (Off the top of my head, I seem to recall you'd have to make it DECIMAL(13, 10) - but that's great until Google changes the resolution at which they're tracking)
 1. The canonical examples that TDWTF brings up are things like 5-digit PIN numbers or phone numbers, just because they look numeric...

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Database column type 'decimal' ignored
« Reply #7, on October 7th, 2012, 02:59 AM »
Float is inherently unreliable beyond a certain point (2^52 for purely whole numbers, but it depends what you're trying to store)

You probably could get away with floats if you were really pushed, but the correct thing to do is use a varchar unless you're planning on doing something that expressly needs it as a number like sorting or searching where distance is a factor.