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(declaredNOT NULLor aPRIMARY KEYmember),pk_ordinal(the column’s 1-based position in the primary key, in key order;NULLfor a non-member),column_default(theDEFAULTas SQL text — an expression default in its stored canonical form, such asuuidv7 ( ), or a constant as a literal of its stored value, such as1.50or'draft';NULLfor no default), andidentity_generation(ALWAYSorBY DEFAULTfor an identity column,NULLotherwise). A view column’stypeis 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 nevernot_null, keyed, or an identity; its view default appears incolumn_default. Views in attached databases are not listed.jed_indexes— one row per secondary index:name,table_name,columns(atext[]of the indexed column names in key order),is_unique,method(btree/gin/gist),predicate(a partial index’sWHEREtext, elseNULL), anddescending/nulls_first(boolean[]s parallel tocolumns: each key’sDESCandNULLS FIRSTflags). The primary key owns no index object, so it is not listed here — seejed_columns.pk_ordinal.jed_constraints— one row perCHECK/UNIQUE/FOREIGN KEY/EXCLUDEconstraint:name,table_name,type,columns(atext[]of the member/local columns;NULLfor aCHECK),expression(theCHECKtext, or a partialEXCLUDEconstraint’sWHEREpredicate;NULLotherwise), andref_table/ref_columns(the foreign-key parent;NULLotherwise),operators(anEXCLUDEconstraint’sWITHoperators,&&or=, in the same order ascolumns;NULLotherwise), andmatch_type(a foreign key’ssimpleorfull;NULLotherwise). AUNIQUEconstraint is its backing unique index, so it appears in bothjed_indexesandjed_constraintsunder 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,NULLfor a column without a GIN operator class). Typed distribution values stay internal; runANALYZEto 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’spg_sequencesspelling),last_value(the last value handed out;NULLuntil the sequence is first read), andowned_by_table/owned_by_column(theserialorIDENTITYcolumn that owns it;NULLfor a standalone sequence).jed_types— one row per user-defined type:nameandkind(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 likejed_columns:type_name,name,ordinal,type(the same canonical type text), andnot_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(atext[]of the output column names, in order), andcheck_option(NONE,LOCAL, orCASCADED), and thesecurity_barrierandsecurity_invokeroptions (booleans). Views are not listed injed_tables; their columns are listed injed_columns, with a view column default ascolumn_default.temp.jed_viewslists the session’s temporary views.
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;(theserialkey shows thenextvaldefault it expands to;DEFAULT 0ondecimal(8,2)shows the stored0.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.