Question

In my DB, I have currently float data. All column are set to be NULLABLE and when value is missing I put there NULL.

My DB is too big and if I know, that values are in range 0 - 100 they can be rounded to 1 decimal place. So using float is overhead and I am thinking of use smallint (multiply every float by 10 and store it as rounded number). Now, what about NULL values. I have two options:

  1. still use NULL

  2. use some "out of bounds" value, like 9999, to represent NULL (and also make this value default, when nothing is set for column). However, in my queries, I need to do this:

    SELECT AVG(NULLIF(data, 9999)) AS data, ....

    (When I use NULL, i can just use AVG(data), while NULL values are not computed..)

What is better to use. Or is there a better technique?

Was it helpful?

Solution 2

Why would you use valid data to represent NULL if you have the opton to actually use NULL itself?

I do not see any benifit

OTHER TIPS

Why would you try to "roll your own" NULL functionality if it already exists? As you describe it, your usage of NULLs is correct and perfectly valid. I don't see any advantage you'd gain by using a magic number as an artificial NULL replacement; you'd just introduce the possibility for errors.

TL;DR: Use NULL.

The NULL value takes the exact same space than a value on a fixed field (float, int...). You can't optimize the space use by not using NULL, or whatever. Sorry :)

When you are using NULL means that you set this column as 'nothing', in the second case you give your column a value that represents the NULL.

So in first your don't have set your column and at second you set a value that shows it is NULL.It depends on what you want to do. If you want to be commitment in your db on that column use the second, else if you want just to be empty unless you fill it use NULL .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top