postgresql - One field with many "precisions" for each data type? -
i have 50 product types in postgresql 9.2.3
database.
some of them divisible, not.
what makes things more complicated "volume"
of different products should have different precision.
product type 1: allowed 8 decimal places. product type 2: integer values. product type 3: 2 decimal places product type 4: 2 decimal places product type 5: 3 ---- || ------ product type 6: 4 ---- || ------ product type 7: 16 ---- || ----- product type 8: integer values product type 9: 4 decimal places product type 10: 5 decimal places product type 11: 12 decimal places
there "orders"
table, 1 products, columns same (user, contractor, order date, shipping price, etc.). exception "volume"
column.
what data type should use?
i thought using "numeric"
field product types + storing info precision every product type , convert values in "orders register" views required precision, wouldn't result in data consistency failures?
in solution there no way check if e.g. integer value 'product type 8' integer, display integer. :(
another way create 1 column per each data type, e.g. volume_int, volume_num_2, volume_num_5, etc, awful. :(
...and solution use table inheritance, that:
orders <- volume integer orders_product_1 (inherits orders) <- volume numeric(24,8) orders_product_2 (inherits orders) <- volume integer orders_product_3 (inherits orders) <- volume numeric(20,2)
...but creating 20 inherited tables seems triumph of form on content...
what best solution? maybe there way solve problem?
use numeric
greatest scale , precision need of values.
if precisions quite static , defined field in same table, can use check
constraint or series of constraints enforce rules values.
if precsions cannot found without lookup table need use trigger enforce rules instead.
the alternative see create type
composite type has value , units/precison stored alongside it. seems heavy handed , pain work with.
Comments
Post a Comment