Guide
A PostgreSQL data dictionary from your schema
A PostgreSQL data dictionary lists each table and view, and each column on it: the name, the data type, whether the column allows null, keys the role can see, and the comment stored on the column. It describes structure. It does not contain the rows stored in those columns.
DictionaryLeap does not connect to PostgreSQL. Run the SELECT below, save the result as a CSV with the header row, and upload that file. The upload reads table_name, column_name, and data_type. table_schema, is_nullable, constraint_type, and the referenced table and column are used when they are present. A comment or column_comment value is stored on the column when that header is present.
The free preview shows the first 25 columns and the first glossary domain. The Dataset Pack is $49 for one table of up to 200 columns, with a flat glossary plus one domain of the hierarchy, and a glossary CSV and SKOS for that domain. The Database Pack is $249 for up to 50 tables and 2,000 columns, with the full glossary and taxonomy hierarchy, all parent and child checks, an Excel glossary sheet, a glossary CSV, and SKOS. Each pack is a one-time price for that upload. It is not a subscription, and nothing renews.
What the dictionary covers
Schema, table or view, and column name. information_schema.columns shows columns the current user can access, by ownership or some other privilege. System schemas pg_catalog and information_schema are left out of this query.
Data type. information_schema.data_type is the SQL type name without length. On a local PostgreSQL 16.15 server, varchar(40) came back as character varying, numeric(10,2) came back as numeric, text[] came back as ARRAY, jsonb stayed jsonb, and an enum came back as USER-DEFINED. This query uses pg_catalog.format_type for the data_type column instead, so those came back as character varying(40), numeric(10,2), text[], jsonb, and app.shade. If the catalog join finds no attribute, the query falls back to information_schema.data_type.
is_nullable, YES or NO. Primary key and foreign key, when the role can see constraints. A column that is both is labeled PRIMARY KEY, FOREIGN KEY, and the referenced table and column are filled. If a column has more than one foreign key, one referenced pair is kept, chosen by constraint name.
The column comment from pg_catalog.col_description. That function takes the table OID and pg_attribute.attnum. The query joins pg_class and pg_attribute on schema, table, and column name. It does not pass ordinal_position. On PostgreSQL 16.15, ordinal_position was attnum, including a gap after a dropped column. The join does not depend on that.
What the CSV should contain
Use these header names. Letter case does not matter. A catalog file needs table_name, column_name, and data_type (or udt_name). The other columns are optional.
| Column | Required | What it is |
|---|---|---|
table_schema | No | Schema name. Keeps two tables with the same name apart. |
table_name | Yes | Table or view name. |
column_name | Yes | Column name. |
data_type | Yes | Type from pg_catalog.format_type, or information_schema.data_type if the attribute join misses. |
is_nullable | No | YES or NO. |
constraint_type | No | PRIMARY KEY, FOREIGN KEY, or PRIMARY KEY, FOREIGN KEY. |
referenced_table_name | No | Table a foreign key points at. |
referenced_column_name | No | Column a foreign key points at. |
comment | No | Column comment from pg_catalog. column_comment is also accepted as the header. |
How to do it
- Run the query. Run the SELECT in the database you want to document. It reads catalog views and functions only.
- Save the CSV. Save the result as a CSV with the header row. Add a schema filter first if you want one schema.
- Start the preview. Upload the file on the build page. Leave sample values off. DictionaryLeap does not connect to PostgreSQL.
- Read the draft. The free preview shows the first 25 columns and the first glossary domain. Sensitivity tags are potential. A data owner confirms the glossary.
Read-only SQL
Run one query. Save the result as a CSV with the header row. Do not include a dump of table rows.
information_schema.columns and pg_catalog comments
This query was run on a local PostgreSQL 16.15 server. The schema had tables, a view, a composite primary key, a column that was both a primary key and a foreign key, column comments, a dropped column, an array, and an enum. It was not run on a production database. The table owner saw the keys. A role with USAGE on the schema and SELECT on the tables saw names, types, nullability, and comments, and the key fields were empty.
The statement is a single SELECT. It does not insert, update, or delete, and it does not read rows from your tables. information_schema.columns includes tables and views. Add AND c.table_schema = 'public' (use your schema name) when you do not want every schema the role can see.
Comments are not a column of information_schema.columns. pg_catalog.col_description reads them. PostgreSQL documents the arguments as the table OID and the column number. The column number is pg_attribute.attnum. Joining on the column name keeps the comment on that column after a drop, when attnum is no longer a dense 1, 2, 3 sequence.
CSV query
SELECT
c.table_schema,
c.table_name,
c.column_name,
COALESCE(pg_catalog.format_type(attr.atttypid, attr.atttypmod), c.data_type) AS data_type,
c.is_nullable,
CASE
WHEN pk.column_name IS NOT NULL AND fk.column_name IS NOT NULL THEN 'PRIMARY KEY, FOREIGN KEY'
WHEN pk.column_name IS NOT NULL THEN 'PRIMARY KEY'
WHEN fk.column_name IS NOT NULL THEN 'FOREIGN KEY'
ELSE NULL
END AS constraint_type,
fk.referenced_table_name,
fk.referenced_column_name,
pg_catalog.col_description(cls.oid, attr.attnum) AS comment
FROM information_schema.columns AS c
LEFT JOIN pg_catalog.pg_namespace AS ns
ON ns.nspname = c.table_schema
LEFT JOIN pg_catalog.pg_class AS cls
ON cls.relnamespace = ns.oid
AND cls.relname = c.table_name
LEFT JOIN pg_catalog.pg_attribute AS attr
ON attr.attrelid = cls.oid
AND attr.attname = c.column_name
AND attr.attnum > 0
AND NOT attr.attisdropped
LEFT JOIN (
SELECT DISTINCT
kcu.table_schema,
kcu.table_name,
kcu.column_name
FROM information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON kcu.constraint_catalog = tc.constraint_catalog
AND kcu.constraint_schema = tc.constraint_schema
AND kcu.constraint_name = tc.constraint_name
WHERE tc.constraint_type = 'PRIMARY KEY'
) AS pk
ON pk.table_schema = c.table_schema
AND pk.table_name = c.table_name
AND pk.column_name = c.column_name
LEFT JOIN (
SELECT DISTINCT ON (kcu.table_schema, kcu.table_name, kcu.column_name)
kcu.table_schema,
kcu.table_name,
kcu.column_name,
ref.table_name AS referenced_table_name,
ref.column_name AS referenced_column_name
FROM information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON kcu.constraint_catalog = tc.constraint_catalog
AND kcu.constraint_schema = tc.constraint_schema
AND kcu.constraint_name = tc.constraint_name
JOIN information_schema.referential_constraints AS rc
ON rc.constraint_catalog = tc.constraint_catalog
AND rc.constraint_schema = tc.constraint_schema
AND rc.constraint_name = tc.constraint_name
LEFT JOIN information_schema.key_column_usage AS ref
ON ref.constraint_catalog = rc.unique_constraint_catalog
AND ref.constraint_schema = rc.unique_constraint_schema
AND ref.constraint_name = rc.unique_constraint_name
AND ref.ordinal_position = kcu.position_in_unique_constraint
WHERE tc.constraint_type = 'FOREIGN KEY'
ORDER BY kcu.table_schema, kcu.table_name, kcu.column_name, kcu.constraint_name
) AS fk
ON fk.table_schema = c.table_schema
AND fk.table_name = c.table_name
AND fk.column_name = c.column_name
WHERE c.table_schema NOT IN ('pg_catalog', 'information_schema')
ORDER BY c.table_schema, c.table_name, c.ordinal_position;Save the result as a CSV with the header row. If a column has more than one foreign key, the query keeps one referenced pair, chosen by constraint name.
The schema export guide uses information_schema.data_type without length, and it does not select comments. This query adds both. That guide also documents pg_dump. It says a schema-only dump on a local server wrote keys as ALTER TABLE, which the upload does not read. Use this CSV when you want keys and comments.
Sensitivity flags and the glossary
DictionaryLeap flags potential sensitivity from the column name. A name such as email, phone, or a government identifier can be tagged. The tag is potential. It is not legal advice, and it does not mean the column was inspected for personal data. This query does not select row values, so the file has no sample of what the column stores.
Healthcare, Financial services, and Retail are optional industry presets on the upload form. A preset adds terms and sensitivity rules when column names match. Any other choice uses the General preset. The preset does not change the price.
The draft includes a business glossary and taxonomy: domains, subject areas, and terms. Definitions are drafts for a data owner to confirm. The free preview shows the first glossary domain. The Dataset Pack includes a flat glossary plus one domain of the hierarchy, a glossary CSV, and SKOS for that domain. The Database Pack includes the full glossary and taxonomy hierarchy, all parent and child checks, an Excel glossary sheet, a glossary CSV, and SKOS.
A comment or column_comment value is stored on the column. The draft can quote it as a source comment when the text is at least 8 characters. Longer text is shortened to 140 characters. An empty comment is fine. Names and types are enough.
Questions about a file or a charge: contact@logicalleap.io.
FAQ
Start the free preview
The free preview shows the first 25 columns and the first glossary domain. The Dataset Pack is $49 for one table of up to 200 columns, with a flat glossary plus one domain of the hierarchy, and a glossary CSV and SKOS for that domain. The Database Pack is $249 for up to 50 tables and 2,000 columns, with the full glossary and taxonomy hierarchy, all parent and child checks, an Excel glossary sheet, a glossary CSV, and SKOS. Each pack is a one-time price for that upload. It is not a subscription, and nothing renews.
Start the free preview