postgresql - What is the best way to select records from value/unit table? -


i have hard_drives table columns producent, size, unit

samsung|256|gb caviar |850|mb sandisc|512|gb seagate|2  |tb 

i'd create queries selecting hard drives size > 128gb, size < 1000mb, size < 1tb etc.

would add new column size_in_bytes, or create conversion table storage_units columns unit, size_in_bytes , use calculations, or maybe there better way perform such queries?

you should use common unit, mb, storing disk sizes. workaround, can use case expression in where clause:

select * yourtable     case when unit = 'mb' size          when unit = 'gb' 1000*size          when unit = 'tb' 1000*1000*size end > 128*1000   -- size > 128gb 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -