简体   繁体   中英

PostgreSQL range containment operator @> not working as expected for the upper boundary

Postgres range datatype's "contains" operator is not working as I expect it. Can anyone help me to solve this

select INT4RANGE(1,5) @> 5 giving false result, where it should be true because 5 in that range

Ranges that don't specify if the bounds are inclusive or exclusive are created with exclusive upper bound

he two-argument form constructs a range in standard form (lower bound inclusive, upper bound exclusive)

So int4range(1,5) is the same as int4range(1,5,'[)') which excludes the value 5.

If you want the 5 to be included, create the range with an inclusive upper bound: int4range(1,5,'[]')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM