- Schema and table names
- Column names (supports composite keys)
- Primary key definitions
Database Editions
ChartDB supports multiple PostgreSQL editions:- Standard PostgreSQL: Full-featured open-source database
- Supabase: Filters out internal schemas (auth, extensions, pgsodium, realtime, storage, vault)
- TimescaleDB: Filters out TimescaleDB internal schemas and tables
Smart Query Import
The PostgreSQL Smart Query extracts complete schema metadata in a single query execution.Standard PostgreSQL Query
For psql command-line usage, ChartDB provides a pre-formatted version with escaped characters:
What the Smart Query Retrieves
The PostgreSQL Smart Query extracts:Foreign Keys (fk_info)
Foreign Keys (fk_info)
- Schema and table names
- Column names
- Foreign key constraint names
- Referenced schema, table, and column
- Full FK definition from
pg_get_constraintdef()
Primary Keys (pk_info)
Primary Keys (pk_info)
Columns (cols)
Columns (cols)
- Data types (including automatic serial type detection)
- Character maximum length
- Numeric precision and scale
- Nullable constraints
- Default values (excluding serial sequences)
- Identity columns (GENERATED AS IDENTITY)
- Array types
- User-defined types
Indexes (indexes_metadata)
Indexes (indexes_metadata)
- Index names and types (btree, hash, gin, gist, etc.)
- Indexed columns and positions
- Unique constraints
- Index size and cardinality
- Sort direction (ASC/DESC)
Custom Types (custom_types)
Custom Types (custom_types)
- ENUM types: Name, schema, and all enum values
- COMPOSITE types: Name, schema, and field definitions
Check Constraints
Check Constraints
- Schema and table names
- Constraint expressions
Views
Views
- Schema and view names
- View definitions (empty in base query)
SQL Import
ChartDB can parse PostgreSQL DDL scripts with support for:Supported Features
- Table Creation: CREATE TABLE with all column types
- Data Types: All PostgreSQL types including:
- Serial types (serial, bigserial, smallserial)
- Arrays (integer[], text[], etc.)
- User-defined types and enums
- Numeric types with precision/scale
- Character types with length
- Timestamp types (with/without timezone)
- Constraints:
- PRIMARY KEY (inline and table-level)
- FOREIGN KEY (inline REFERENCES and table-level)
- UNIQUE constraints
- CHECK constraints
- NOT NULL
- Custom Types:
- CREATE TYPE … AS ENUM
- CREATE TYPE … AS (composite types)
- Indexes: CREATE INDEX and CREATE UNIQUE INDEX
- Views: CREATE VIEW and CREATE OR REPLACE VIEW
- Schemas: Multi-schema support
- Sequences: CREATE SEQUENCE
- Comments: Single-line (—) and multi-line (/* */)
Import Example
- The custom
user_roleenum - The
appschema - All column types including arrays and jsonb
- Foreign key relationship between posts and users
- Check constraints
- Indexes
- Default values
SQL Export
Export your ChartDB diagrams to production-ready PostgreSQL SQL.Export Features
- Schema Creation: CREATE SCHEMA IF NOT EXISTS statements
- Custom Types: ENUMs and composite types with proper ordering
- Sequences: Automatic sequence creation for serial types
- Serial Types: Converts integer+identity to serial/bigserial/smallserial
- Array Types: Preserves array notation (e.g., integer[])
- Constraints:
- Primary keys as table constraints
- Unique constraints (avoids redundant PK indexes)
- Check constraints
- Foreign keys with ON DELETE/ON UPDATE
- Indexes: Separate CREATE INDEX statements
- Comments: Table and column comments using COMMENT ON
- Quoted Identifiers: Proper quoting for reserved words and special characters
Export Example
PostgreSQL-Specific Features
Serial Types
ChartDB automatically handles PostgreSQL serial types:- serial (serial4): Converts to/from integer with sequence
- bigserial (serial8): Converts to/from bigint with sequence
- smallserial (serial2): Converts to/from smallint with sequence
Array Types
Full support for PostgreSQL arrays:Custom Types
ENUM Types:GENERATED Identity Columns
Support for SQL standard identity columns:Best Practices
Use schemas for organization
Organize your tables into logical schemas (e.g.,
public, auth, analytics)Troubleshooting
Query execution timeout
Query execution timeout
For very large databases, increase the statement timeout:
Permission denied errors
Permission denied errors
Ensure your database user has SELECT permissions on system catalogs:
pg_constraintpg_attributepg_classpg_namespaceinformation_schema.columns
Missing custom types
Missing custom types
Custom types are only retrieved from non-system schemas. Ensure your types are not in
pg_catalog or information_schema.