isfinite Separates Real From Infinite Values

Test dates, timestamps, and intervals with isfinite, which flags the infinity literals that stand in for open-ended ranges.

SqlData Integrity

Code

snippet
-- isfinite 有 date、timestamp、interval 三个变体
SELECT
    isfinite('2026-05-01'::date)               AS plain_date,
    isfinite('infinity'::date)                 AS far_future_date,
    isfinite('-infinity'::timestamp)           AS distant_past_ts,
    isfinite('2026-05-01 09:30:00'::timestamp) AS real_moment,
    isfinite('90 days'::interval)              AS finite_interval;

-- 开放端点的有效期用 infinity 表示"没有截止日"
CREATE TABLE memberships (
    member     text PRIMARY KEY,
    valid_from date NOT NULL,
    valid_to   date NOT NULL DEFAULT 'infinity'
);

INSERT INTO memberships VALUES ('ada', '2024-01-01');

-- isfinite 把"有截止日"与"永不过期"区分开
SELECT
    member,
    valid_to,
    isfinite(valid_to) AS has_expiry,
    CASE WHEN isfinite(valid_to)
         THEN valid_to::text
         ELSE 'no end date' END AS expiry_label
FROM memberships;

What the code does

What runs here is SELECT / INSERT / CREATE — memberships are the objects involved.

The pieces that do the work: NOT NULL qualifiers on the required columns; a PRIMARY KEY that enforces row identity; DEFAULT values filling omitted columns.

Using it

The memberships table is the working surface here.

Key statements

SELECT
    member,
    valid_to,
    isfinite(valid_to) AS has_expiry,
    CASE WHEN isfinite(valid_to)
         THEN valid_to::text
         ELSE 'no end date' END AS expiry_label
FROM memberships;
CREATE TABLE memberships (
    member     text PRIMARY KEY,
    valid_from date NOT NULL,
    valid_to   date NOT NULL DEFAULT 'infinity'
);
INSERT INTO memberships VALUES ('ada', '2024-01-01');

Interactive Tools for This Topic

FAQ

What objects does the SQL involve?
`memberships` — referenced directly, no join needed.