PostgreSQL ISFINITE() Function
Summary: in this tutorial, you will learn how to use the PostgreSQL ISFINITE()
function to determine if a date, a timestamp, or an interval is finite or not.
Introduction to the PostgreSQL ISFINITE() function
The ISFINITE()
function accepts a date, a timestamp, or an interval and returns true if the value is finite.
Here’s the syntax of the ISFINITE()
function:
The isfinite()
function accepts a value with the type date, timestamp, or interval.
The isfinite()
function returns true if the value is finite or false otherwise. It returns NULL
if the value is NULL
.
PostgreSQL ISFINITE() function examples
Let’s explore some examples of using the ISFINITE()
function.
1) Using the ISFINITE() function with dates
The following example uses the ISFINITE()
function to check if a date is finite or not:
Output:
The result is t, which is true in PostgreSQL.
The following example uses the ISFINITE()
function to determine whether the date infinity is finite or not:
Output:
The result is false because the infinity date is not finite.
2) Using the ISFINITE() function with intervals
The following statement uses the ISFINITE()
function to check if an interval is finite or not:
Output:
Since PostgreSQL doesn’t support infinity intervals, the ISFINITE()
function always returns true for an interval.
3) Using the ISFINITE() function with timestamps
The following statement uses the ISFINITE()
function to test for a finite timestamp:
Output:
The following statement uses the ISFINITE()
function to check for an infinite timestamp:
Output:
Summary
- Use the
ISFINITE()
function to test if a date, a timestamp, or an interval is finite or not.