0

I'd like to save IP address ranges in 2 columns and determine regarding some IP address if it's in this range by "greater than" and "less than" operators. Will it work if I save the ranges as VARCHAR ?

JGH
  • 15,928
  • 4
  • 31
  • 48
sharon182
  • 533
  • 1
  • 4
  • 19
  • https://stackoverflow.com/questions/24944075/postgres-check-if-ip-inet-is-in-a-list-of-ip-ranges you can check if belongs to `array():inet[]` – Vao Tsun May 23 '17 at 15:26

2 Answers2

2

Postgres has network address types that support those operators.

Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54
1

No, it would not work. Comparing number in string is a bad idea, as '11' is considered smaller than '2' (comparing the 1st char, 2 > 1, so 2nd string is greater than the 1st one). Should you not want to use the network type, you would have more luck using bigint with proper padding

JGH
  • 15,928
  • 4
  • 31
  • 48