2

I am using Postgres 9.3.

I have to store range data like <250ドルK, 250ドルK-4ドルM, etc which we will display in a dropdown.

now I am making a table for all possible options that can be configured from an admin interface.

Should I take separate column for min,max,currency_type(dollar,euro) and a column to store K,M etc or there is a better way to do that ?

Kilian Foth
111k45 gold badges301 silver badges323 bronze badges
asked Feb 6, 2014 at 11:59
6
  • 1
    Three columns: Start, End, CurrencyType. E.g. 0, 250, USD Commented Feb 6, 2014 at 12:12
  • 1
    just a suggestion: do not store K or M (order of magnitude) in the database. This is considered display/formatting logic and can be calculated on the fly. I'd even go as far as saying it should be calculated on the fly because it is a more flexible approach. Commented Feb 6, 2014 at 12:51
  • @MetaFight: More importantly, you can't compare 5K to 4M. But you can compare 5000 and 4000000. So you can't do things like finding the overlaps in ranges. Of course, if you're not going to do all of that, you might as easily store the range as a display string. Commented Feb 6, 2014 at 12:54
  • I am using postgres datatype range. that should be fine right ? Commented Feb 6, 2014 at 14:35
  • What relevance does the range data type have here? Commented Feb 6, 2014 at 17:05

2 Answers 2

1

Guessing you will be needing ranges for different kinds of dropdowns;

enter image description here

answered Feb 7, 2014 at 0:21
0

If these are intended to be all-encompassing ranges that all values must fall within, I'd just store either the maximum or minimum value of the range in a single column.

ID | Amount 
-----------
 1 | 0
 2 | 250000 
 3 | 500000 
 4 |1000000 
 5 |2000000

You can calculate the actual ranges on the fly from this.

answered Feb 6, 2014 at 17:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.