Welcome to the new DOCS.vastdata.com. We've added new menus and a version selector, plus new persona and resource pages to help customers get started. Looking for a previous article? Use the docs search.

isfinite

Prev Next

Applies to VAST Cluster 5.5.

Functions › Date and time functions › Special values. Returns true if a date or timestamp is an ordinary value, and false if it's one of the special values 'infinity' or '-infinity'. It's the opposite of isinf.

Syntax

isfinite(value)
Argument Type Description
value DATE, TIMESTAMP (also TIMESTAMP_NS, TIMESTAMP_MS, TIMESTAMP_S) or TIMESTAMP WITH TIME ZONE The value to test.

Returns: BOOLEAN.

isfinite also takes a FLOAT or DOUBLE; see isfinite for numbers.

Set up the examples

The examples connect with the ADBC driver, as in VAST Query Engine (ADBC), and work in a schema called docs_sql_fn_date_time_isfinite. Set QE_ENDPOINT, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and VASTDB_BUCKET (SQL reference), and run the blocks in order in one Python session. Below each block is the output you should see.

This block connects, defines the run() and plan() helpers, and creates a table of five events. Each has a date (d), a timestamp (ts), a time of day (t) and a timestamp with nanoseconds (tns). Row 4 has no values, and row 5 is the last moment of 1969:

import os
import re

import adbc_driver_manager
import adbc_driver_manager.dbapi as dbapi
import adbc_driver_vastdb

BUCKET = os.environ["VASTDB_BUCKET"]
SCHEMA = f'"{BUCKET}/docs_sql_fn_date_time_isfinite"'

conn = dbapi.connect(
    driver=adbc_driver_vastdb.get_driver_path(),
    db_kwargs={
        "vast.db.endpoint": os.environ["QE_ENDPOINT"],
        "vast.db.access_key": os.environ["AWS_ACCESS_KEY_ID"],
        "vast.db.secret_key": os.environ["AWS_SECRET_ACCESS_KEY"],
    },
    autocommit=True,
)

def server_message(e):
    """The server's message in a driver error, without the request ID or the echoed statement."""
    text = re.sub(r"\[req=0x[0-9a-f]+\]: ", "", str(e))
    found = (re.search(r'message: "(.*?)", request_id', text, re.S)
             or re.search(r"description: (.*)\)", text, re.S))
    message = found.group(1) if found else text.strip().splitlines()[-1]
    message = re.sub(r"^Plan query: '.*?' failed with: ", "", message, flags=re.S)
    message = re.split(r"\\n|\n", message)[0].replace('\\"', '"')
    return message.replace(BUCKET, "<bucket>")

def run(sql):
    """Run one statement. Print the rows it returns, or the error."""
    try:
        with conn.cursor() as cur:
            cur.execute(sql)
            rows = cur.fetchall() if cur.description else []
    except (adbc_driver_manager.Error, OSError) as e:
        print(f"{type(e).__name__}: {server_message(e)}")
    else:
        print(rows)

def plan(sql):
    """Print the plan without its ~N Rows lines: the table's row count, which can still be 0 just after an insert."""
    with conn.cursor() as cur:
        cur.execute("EXPLAIN " + sql)
        steps = cur.fetchall()[0][1]
    print("\n".join(line for line in steps.splitlines() if "Rows" not in line))

TABLE = f"{SCHEMA}.events"
run(f"CREATE SCHEMA IF NOT EXISTS {SCHEMA}")
run(f"CREATE TABLE IF NOT EXISTS {TABLE} (id BIGINT, d DATE, ts TIMESTAMP, t TIME, tns TIMESTAMP_NS)")
run(f"INSERT INTO {TABLE} VALUES "
    "(1, DATE '2026-02-28', TIMESTAMP '2026-02-28 23:15:00', TIME '23:15:00', "
    "CAST('2026-02-28 23:15:00.123456789' AS TIMESTAMP_NS)), "
    "(2, DATE '2026-03-01', TIMESTAMP '2026-03-01 08:30:45.123456', TIME '08:30:45.123456', "
    "CAST('2026-03-01 08:30:45.123456' AS TIMESTAMP_NS)), "
    "(3, DATE '2024-12-30', TIMESTAMP '2024-12-30 12:00:00', TIME '12:00:00', "
    "CAST('2024-12-30 12:00:00' AS TIMESTAMP_NS)), "
    "(4, NULL, NULL, NULL, NULL), "
    "(5, DATE '1969-12-31', TIMESTAMP '1969-12-31 23:59:59.999999', TIME '23:59:59.999999', "
    "CAST('1969-12-31 23:59:59.999999999' AS TIMESTAMP_NS))")
[]
[]
[(5,)]

What it does

A DATE or timestamp can hold two special values besides ordinary dates: 'infinity', later than every date, and '-infinity', earlier than every date. Write them as DATE 'infinity', TIMESTAMP '-infinity' and so on.

isfinite returns true for every ordinary value, however far in the past or future (isfinite(DATE '0001-01-01') and isfinite(DATE '9999-12-31') are true), and false for either special value. It works the same on every timestamp precision and on a TIMESTAMP WITH TIME ZONE. For a non-NULL value, isfinite(v) is always NOT isinf(v).

Most date and time functions return NULL for a special value (for example, year(DATE 'infinity')), so use isfinite to keep only the values they can work on.

NULLs and edge cases

Input Result
NULL, or a NULL value (row 4) NULL
DATE 'infinity', DATE '-infinity' false
TIMESTAMP 'infinity', TIMESTAMP '-infinity' false
CAST('infinity' AS TIMESTAMP_NS), TIMESTAMPTZ 'infinity' false
DATE '0001-01-01', DATE '9999-12-31', 44 BC true
A TIME Error: No function matches the given name and argument types 'isfinite(TIME)'
An INTERVAL Error: No function matches the given name and argument types 'isfinite(INTERVAL)'
A string Error: Could not choose a best candidate function; cast it to DATE or TIMESTAMP first
A boolean, BLOB or list Error: No function matches the given name and argument types, for example 'isfinite(BOOLEAN)'
A number, such as isfinite(1.5) true: the number form

The same cases, as the cluster returns them. They use the table and helpers from Set up the examples:

run(f"SELECT id, isfinite(d), isfinite(ts) FROM {TABLE} WHERE id = 4")
run("SELECT isfinite(NULL), isfinite(DATE 'infinity'), isfinite(DATE '-infinity'), isfinite(TIMESTAMP 'infinity'), "
    "isfinite(TIMESTAMP '-infinity'), isfinite(CAST('infinity' AS TIMESTAMP_NS)), isfinite(TIMESTAMPTZ 'infinity')")
run("SELECT isfinite(DATE '0001-01-01'), isfinite(DATE '9999-12-31'), isfinite(CAST('0044-03-15 (BC)' AS DATE)), "
    "isfinite(1.5)")
run("SELECT isfinite(TIME '13:45:30')")
run("SELECT isfinite(INTERVAL '1 day')")
run("SELECT isfinite('2024-02-29')")
run("SELECT isfinite(true)")
[(4, None, None)]
[(None, False, False, False, False, False, False)]
[(True, True, True, True)]
InternalError: Binder Error: No function matches the given name and argument types 'isfinite(TIME)'. You might need to add explicit type casts.
InternalError: Binder Error: No function matches the given name and argument types 'isfinite(INTERVAL)'. You might need to add explicit type casts.
InternalError: Binder Error: Could not choose a best candidate function for the function call "isfinite(STRING_LITERAL)". In order to select one, please add explicit type casts.
InternalError: Binder Error: No function matches the given name and argument types 'isfinite(BOOLEAN)'. You might need to add explicit type casts.

Examples

Every event in the table has an ordinary date and timestamp, so isfinite is true for each, and NULL for row 4:

run(f"SELECT id, isfinite(d), isfinite(ts), isfinite(tns) FROM {TABLE} ORDER BY id LIMIT 10")
[(1, True, True, True), (2, True, True, True), (3, True, True, True), (4, None, None, None), (5, True, True, True)]

Keep only the rows with an ordinary date. Row 4 is left out because isfinite(NULL) is NULL, not true:

run(f"SELECT id FROM {TABLE} WHERE isfinite(d) ORDER BY id LIMIT 10")
[(1,), (2,), (3,), (5,)]

How it runs in VAST

The Query Engine runs on the cluster's CNodes, and a query on a table starts with a scan in VAST DataBase (VAST_SCAN). VAST DataBase can evaluate a comparison of a column with a constant, but not a function of a column, so isfinite() is always computed by the Query Engine:

  • In the SELECT list, the scan reads the column and the Query Engine computes isfinite() for each row it returns.
  • In WHERE, the scan sends the column for every row, and a FILTER step in the Query Engine computes isfinite() and keeps the rows that match. No rows are skipped in storage.

The plan of the WHERE example shows the FILTER step above the scan:

plan(f"SELECT id FROM {TABLE} WHERE isfinite(d)")
┌───────────────────────────┐
│         PROJECTION        │
│    ────────────────────   │
│             #1            │
│                           │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│           FILTER          │
│    ────────────────────   │
│        isfinite(d)        │
│                           │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│         VAST_SCAN         │
│    ────────────────────   │
│    Function: VAST_SCAN    │
│                           │
│        Projections:       │
│             d             │
│             id            │
│                           │
└───────────────────────────┘

Make it faster

  • Combine it with a pushed-down condition. In id > 2 AND isfinite(d), id > 2 is still evaluated in VAST DataBase, so isfinite() runs only on the rows that pass it. In the plan, the FILTER step holds only isfinite(d):
plan(f"SELECT id FROM {TABLE} WHERE id > 2 AND isfinite(d)")
┌───────────────────────────┐
│         PROJECTION        │
│    ────────────────────   │
│             #0            │
│                           │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│           FILTER          │
│    ────────────────────   │
│        isfinite(d)        │
│                           │
└─────────────┬─────────────┘
┌─────────────┴─────────────┐
│         VAST_SCAN         │
│    ────────────────────   │
│    Function: VAST_SCAN    │
│                           │
│        Projections:       │
│             id            │
│             d             │
│                           │
└───────────────────────────┘
  • Store a flag if you filter on it often. Compute isfinite(d) when you write the rows and keep it in a BOOLEAN column: a comparison of that column is pushed down, isfinite(d) isn't.

Limitations and errors

  • Dates and timestamps only. A TIME or an INTERVAL has no special values; isfinite fails with No function matches the given name and argument types.
  • Not for strings. A string fails with Could not choose a best candidate function. Cast it first: isfinite(CAST('2024-02-29' AS DATE)).
  • One argument. isfinite(ts, ts) fails with No function matches the given name and argument types 'isfinite(TIMESTAMP, TIMESTAMP)'.
run("SELECT isfinite(CAST('2024-02-29' AS DATE))")
run(f"SELECT isfinite(ts, ts) FROM {TABLE} LIMIT 1")
[(True,)]
InternalError: Binder Error: No function matches the given name and argument types 'isfinite(TIMESTAMP, TIMESTAMP)'. You might need to add explicit type casts.

Similar functions

Function Returns DATE 'infinity' TIMESTAMP '-infinity' DATE '2026-03-01'
isfinite Whether the value is an ordinary date or time false false true
isinf Whether the value is a special value true true false
run("SELECT isfinite(DATE 'infinity'), isfinite(TIMESTAMP '-infinity'), isfinite(DATE '2026-03-01'), "
    "isinf(DATE 'infinity'), isinf(TIMESTAMP '-infinity'), isinf(DATE '2026-03-01')")
[(False, False, True, True, True, False)]

Clean up:

run(f"DROP TABLE IF EXISTS {TABLE}")
run(f"DROP SCHEMA IF EXISTS {SCHEMA}")
conn.close()
[]
[]

See also