jed

Introspection

The jed_ catalog relations describe a database from SQL. They are ordinary read-only relations — select from them, filter them, join them — whose rows are computed on the fly from the database’s catalog. Nothing is stored, so they are always current.

Nine relations ship today:

  • jed_tables — one row per user table: name (the resolved table name: unquoted identifiers are folded to lowercase).
  • jed_columns — one row per column of every user table and view: table_name (the table or view name), name, ordinal (1-based, declaration order), type (the canonical type text — i32, varchar(80), decimal(8,2), i32[], i32range, a composite’s name, …), not_null (declared NOT NULL or a PRIMARY KEY member), pk_ordinal (the column’s 1-based position in the primary key, in key order; NULL for a non-member), column_default (the DEFAULT as SQL text — an expression default in its stored canonical form, such as uuidv7 ( ), or a constant as a literal of its stored value, such as 1.50 or 'draft'; NULL for no default), and identity_generation (ALWAYS or BY DEFAULT for an identity column, NULL otherwise). A view column’s type is the type a query over the view produces: a column read straight from a table keeps its length or precision (varchar(80)), and a computed one has none (text); a view column is never not_null, keyed, or an identity; its view default appears in column_default. Views in attached databases are not listed.
  • jed_indexes — one row per secondary index: name, table_name, columns (a text[] of the indexed column names in key order), is_unique, method (btree / gin / gist), predicate (a partial index’s WHERE text, else NULL), and descending / nulls_first (boolean[]s parallel to columns: each key’s DESC and NULLS FIRST flags). The primary key owns no index object, so it is not listed here — see jed_columns.pk_ordinal.
  • jed_constraints — one row per CHECK / UNIQUE / FOREIGN KEY / EXCLUDE constraint: name, table_name, type, columns (a text[] of the member/local columns; NULL for a CHECK), expression (the CHECK text, or a partial EXCLUDE constraint’s WHERE predicate; NULL otherwise), and ref_table / ref_columns (the foreign-key parent; NULL otherwise), operators (an EXCLUDE constraint’s WITH operators, && or =, in the same order as columns; NULL otherwise), and match_type (a foreign key’s simple or full; NULL otherwise). A UNIQUE constraint is its backing unique index, so it appears in both jed_indexes and jed_constraints under the same name.
  • jed_statistics — one summary per analyzed column: table/column name, analyzed row and NULL counts, stale flag, optional distinct count, sample rows, average width, MCV/histogram counts, and the GIN term-list length (term_count, NULL for a column without a GIN operator class). Typed distribution values stay internal; run ANALYZE to create or refresh a fact. A successful table write retains its facts and marks them stale.
  • jed_sequences — one row per sequence: name, start_value, min_value, max_value, increment_by, cycle, cache_size (PostgreSQL’s pg_sequences spelling), last_value (the last value handed out; NULL until the sequence is first read), and owned_by_table / owned_by_column (the serial or IDENTITY column that owns it; NULL for a standalone sequence).
  • jed_types — one row per user-defined type: name and kind (composite, the only kind you can create today). Built-in types are not listed.
  • jed_type_fields — one row per field of every composite type, shaped like jed_columns: type_name, name, ordinal, type (the same canonical type text), and not_null.
  • jed_views — one row per view: name, definition (the stored query text, normalized: lowercase keywords, single-spaced tokens, * expanded into explicit columns, and renames applied), columns (a text[] of the output column names, in order), and check_option (NONE, LOCAL, or CASCADED), and the security_barrier and security_invoker options (booleans). Views are not listed in jed_tables; their columns are listed in jed_columns, with a view column default as column_default. temp.jed_views lists the session’s temporary views.
Ctrl/⌘ + Enter to run · in-memory

No results yet. Run a query to see output.

Things to try in the panel above:

  • List the tables — SELECT name FROM jed_tables ORDER BY name;
  • Reconstruct a key — SELECT name FROM jed_columns WHERE table_name = 'booking' AND pk_ordinal IS NOT NULL ORDER BY pk_ordinal;
  • List the indexes — SELECT name, table_name, columns, is_unique, method FROM jed_indexes ORDER BY table_name, name;
  • List the constraints — SELECT name, table_name, type, columns, expression, ref_table, ref_columns, operators FROM jed_constraints ORDER BY table_name, type, name;
  • Inspect planner facts — SELECT table_name, column_name, analyzed_rows, is_stale, distinct_count FROM jed_statistics ORDER BY table_name, column_name;
  • List the sequences — SELECT name, start_value, last_value, owned_by_table, owned_by_column FROM jed_sequences ORDER BY name;
  • Advance one, then look again — SELECT nextval('invoice_no');
  • Describe a composite type — SELECT name, ordinal, type, not_null FROM jed_type_fields WHERE type_name = 'addr' ORDER BY ordinal;
  • Find the columns typed at a user-defined type — SELECT c.table_name, c.name, t.name FROM jed_types t JOIN jed_columns c ON c.type = t.name;
  • Find every foreign key and its parent — SELECT table_name, columns, ref_table, ref_columns, match_type FROM jed_constraints WHERE type = 'foreign_key';
  • Count columns per table — SELECT table_name, count(*) FROM jed_columns GROUP BY table_name;
  • Show the column defaults — SELECT table_name, name, column_default FROM jed_columns WHERE column_default IS NOT NULL; (the serial key shows the nextval default it expands to; DEFAULT 0 on decimal(8,2) shows the stored 0.00)
  • Create a view, then list it — CREATE VIEW adults AS SELECT id, name FROM customer WHERE age >= 18; SELECT name, definition, columns FROM jed_views;
  • Then list its columns and their types — SELECT name, type FROM jed_columns WHERE table_name = 'adults' ORDER BY ordinal;
  • Create a table or index, then re-run the query — the new rows appear immediately.

Scoping — one catalog per database

Every database carries its own catalog relations, reached with the same qualifier as its tables: jed_tables (or main.jed_tables) reads the main database, temp.jed_tables lists the session’s temporary tables (and temp.jed_sequences their owned sequences), and reports.jed_tables lists an attached database’s tables. An unqualified name always means main.

Read-only, and gated like any table

The catalog relations cannot be written or dropped — INSERT/UPDATE/DELETE, CREATE INDEX … ON, and DROP TABLE against one raise error 42809. Creating any relation whose name begins with jed_ is rejected (42939): the prefix is reserved for the engine.

Under a restricted session, a catalog relation is authorized exactly like a user table: a session with explicit grants sees the schema only if the host granted SELECT on that relation. Schema visibility is a policy decision, not a default.

Two practical notes:

  • Select columns by name. The relations grow by adding columns over time, so SELECT * positionally is not a stable contract.
  • The relations list user objects only — they do not list themselves.
jed — an embeddable, strictly-typed SQL database.