-1

I have a numeric[] column in a Postgres database that should represent an array of times (like {0.5 seconds, 2 seconds, 3.25 seconds, ...}). As such I would like to constrain the values in the array to be unique and sorted. Is there any way to do that?

I've seen some answers that bring up the intarray module's sort and uniq functions. Is there anything like that for numeric/decimal?

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228
user1475412
  • 1,659
  • 2
  • 22
  • 30

1 Answers1

0

The additional module intarray is for integer only. You cannot use it for data type numeric and I wouldn't know of any thing like it for numeric, either.

If your numbers have no more than n fractional digits and can be scaled to integer, you can multiply by 10^n and operate with integer instead. Scale back for output ...

Apart from that, I have answered the same question before (sorting is trivial for sets):

Community
  • 1
  • 1
Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228