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.
Code
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
SQL DDL to TypeScript ConverterConvert SQL CREATE TABLE DDL statements into strict TypeScript interfaces with nullable, array, enum, JSONB, and Date or ISO string column mappings.PostgreSQL EXPLAIN AnalyzerAnalyze PostgreSQL EXPLAIN ANALYZE text or FORMAT JSON plans locally to flag Seq Scans, slow nodes, row misestimates, disk sorts, and index hints.Multi-Mode Escape & Unescape CodecEscape and unescape strings safely across JSON, JavaScript, SQL single-quoted literals, POSIX shell single quotes, and RFC 4180 CSV cells in your browser.SPDX License LookupSearch common SPDX license identifiers and see permissions, conditions, limitations, copyleft strength, and OSI or FSF approval status.
FAQ
- Which tables does this file reference?
- `events`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.