Skip to main content

Module pgcatalog

Module pgcatalog 

Source
Expand description

pg_catalog and information_schema as REAL QUERYABLE TABLES.

§Why this exists

\dt in psql and the schema browser in DBeaver came back empty. That is an evaluator’s first ten minutes, and an empty table list does not read as “unsupported” — it reads as “this database is broken” or “my data is gone”.

§Why it is built this way

The cheap implementation is to recognise psql’s exact query text and answer it from a fixed table. Several pgwire-compatible engines do that. It is the wrong choice here for a specific reason: it breaks silently. psql changes its catalogue queries between versions, and when the pattern stops matching, the result is an empty table list — indistinguishable from a database that genuinely has no tables. That is the exact class of confidently-wrong answer this engine has spent its life removing.

So the catalogue is a set of real tables, synthesised from the live database, and queried through the ordinary predicate path (nql::query_rows). WHERE, ORDER BY, LIMIT and the ~/!~ operators all work on them because they are the same operators, not a second implementation.

§What a schemaless engine can honestly report

NEDB has no schema, so the catalogue is derived, and that derivation is stated rather than hidden:

  • a collection is a table in pg_class / information_schema.tables;
  • a field observed in a sampled document is a column in pg_attribute / information_schema.columns, typed the way the pgwire layer types it on the wire;
  • everything Postgres tracks that NEDB does not have — owners, tablespaces, ACLs, statistics — reports a fixed, plainly-wrong-if-you-look value (10, 0, empty) rather than a fabricated plausible one.

Column order and the sampled field set come from the same code the wire protocol uses, so a client is never told about a column the data does not produce.

Functions§

is_catalog
Is table a catalogue relation this module serves?
rows
The rows of a catalogue relation, or None if it is not one.
type_name_pub
The Postgres type name for an OID we hand out — the data_type a client reads in information_schema.columns. Public alias so format_type() in the SQL engine names a type the same way information_schema.columns does.