How to Check if the Lower Bound of the Given Range is Inclusive or Not

PostgreSQL supports several useful built-in functions designed to work with range types. These functions help us handle ranges more efficiently. For example, the lower_inc() tells us if the lower bound is included, and lower() gives us the lowest value in the range, the upper_inc() checks if the upper bound of the specified range is included, and so on.

This post illustrates how to check if the lower bound of the specified range is inclusive or not.

How to Check if the Lower Bound of the Given Range is Inclusive or Not?

In PostgreSQL, the LOWER_INC() function accepts a range or multi-range as an argument and checks if the lower bound of the specified range is inclusive or exclusive.

Syntax

Use the below-stated syntax to execute the LOWER_INC() function on the specified range:

LOWER_INC(range | multirange);

Parameters

This function accepts a single-range or multi-range value as an argument.

Return Type

The return type of LOWER_INC() is Boolean.

Return Value

It retrieves a True or False value which shows if the lower bound of the given range is inclusive or exclusive.

Example 1

This example illustrates how to use the LOWER_INC() function to check if the lower bound is included or excluded:

SELECT LOWER_INC('[0, 10]'::int4range) AS lower_bound_inclusice;

The output snippet shows “true” which indicates that the lower bound is included in the range:

img

Example 2

Let’s try out another example for a better understanding of the LOWER_INC() function in Postgres:

SELECT LOWER_INC('(5, 5)'::int4range) AS lower_bound_inclusice;

The output snippet shows “false” which indicates that the lower bound is not included in the range:

img

Example 3

In the following example, the LOWER_INC() function is applied on the range “[5, 6)”:

SELECT LOWER_INC('[5, 6)'::int4range) AS lower_bound_inclusice;

The output snippet shows that the lower bound is included in the range:

img

This is how the LOWER_INC() function works in PostgreSQL.

Conclusion

In PostgreSQL, the LOWER_INC() function accepts a range or multi-range as an argument and checks if the lower bound of the specified range is inclusive or exclusive. The return type of the LOWER_INC() is Boolean. It retrieves a True or False value which shows if the lower bound of the given range is inclusive or exclusive. This post has demonstrated the various use cases of the LOWER_INC() function in PostgreSQL using practical examples.