Skip to content
Advertisement

Getting the outer range of a grouped column of range types in Postgres

I have a table with a column name consisting of text values that I want to group by. Additionally I have a table value consisting of numerical range values (of range type). I want to group by the name column and get the outer bounds for each of the groups.

Here is an example:

Parameter table

Wanted output is something like this (or lower, upper bound in separate columns):

Here is a query I attempted to run, but it failed:

Is there a way to achieve this is Postgresql?

Advertisement

Answer

You need to use an aggregate function, e.g.: min(lower(value)). From there you can create a new range:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement