Tableoid Points At The Source Partition

The tableoid system column identifies the physical partition holding each row, so queries can attribute and count rows per partition.

SqlData Integrity

Code

snippet
CREATE TABLE events (
    id         bigint GENERATED ALWAYS AS IDENTITY,
    kind       text NOT NULL,
    created_at timestamptz NOT NULL
) PARTITION BY RANGE (created_at);

CREATE TABLE events_2026_05 PARTITION OF events
    FOR VALUES FROM ('2026-05-01') TO ('2026-06-01');
CREATE TABLE events_2026_06 PARTITION OF events
    FOR VALUES FROM ('2026-06-01') TO ('2026-07-01');

INSERT INTO events (kind, created_at) VALUES
    ('signup', '2026-05-14 09:00+00'),
    ('signup', '2026-06-02 11:30+00');

-- tableoid carries the oid of the physical table the row lives in
SELECT kind, created_at, tableoid::regclass AS stored_in
FROM events
ORDER BY created_at;

-- count rows per physical partition without listing partition names
SELECT tableoid::regclass AS partition, count(*)
FROM events
GROUP BY tableoid
ORDER BY partition;

Reading the code — Tableoid Points At The Source Partition

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

Clause by clause, expect: COUNT aggregation; a GROUP BY that collapses matching rows into one output row per group; an ORDER BY that fixes the output order; NOT NULL qualifiers on the required columns; a GENERATED ALWAYS/GENERATED BY clause that computes the column value.

Applying it

The events table is the working surface here.

Statements that matter

SELECT tableoid::regclass AS partition, count(*)
FROM events
GROUP BY tableoid
ORDER BY partition;
CREATE TABLE events (
    id         bigint GENERATED ALWAYS AS IDENTITY,
    kind       text NOT NULL,
    created_at timestamptz NOT NULL
) PARTITION BY RANGE (created_at);
CREATE TABLE events_2026_05 PARTITION OF events
    FOR VALUES FROM ('2026-05-01') TO ('2026-06-01');

Interactive Tools for This Topic

FAQ

Which tables does this file reference?
`events`.