PostgreSQL Adapter
The PostgreSQL adapter provides comprehensive support for PostgreSQL databases with advanced features like schemas, detailed statistics, and constraint introspection.Installation
Basic Usage
Configuration Options
Execute Function
Using pg (node-postgres)
Using pg with connection string
Schema Filtering
Limit introspection to specific schemas:schemas, system schemas are excluded automatically:
pg_cataloginformation_schema
Grounding Functions
All PostgreSQL grounding functions:PostgreSQL-Specific Features
Schema Support
PostgreSQL organizes tables into schemas:Identifier Quoting
PostgreSQL uses double quotes:String Escaping
PostgreSQL escapes single quotes by doubling:LIMIT Clause
Advanced Statistics
PostgreSQL provides rich column statistics frompg_stats:
- correlation - Physical row order correlation with logical sort order
- n_distinct - Estimated number of distinct values
- null_frac - Fraction of NULL values
- min/max - Minimum and maximum values
Error Handling
PostgreSQL errors are classified by error code:| Error Code | Type | Suggestion |
|---|---|---|
| 42P01 | MISSING_TABLE | Check the database schema for the correct table name |
| 42703 | INVALID_COLUMN | Verify the column exists and use table aliases |
| 42601 | SYNTAX_ERROR | Review keywords, punctuation, and query shape |
| 42P10 | INVALID_COLUMN | Columns in GROUP BY/SELECT must exist |
| 42883 | INVALID_FUNCTION | Function or operator not recognized |
Complete Example
postgres-example.ts
Connection Pooling
Use connection pooling for better performance:SSL Connections
Connect securely:Performance Tips
1. Use Indexes
PostgreSQL supports multiple index types:2. Analyze Statistics
Keep statistics up to date:3. Use Partial Indexes
Index only relevant rows:4. Optimize Introspection
Advanced Features
JSON Support
PostgreSQL JSON columns work seamlessly:Array Support
Full-Text Search
Window Functions
Best Practices
1. Use Schemas for Organization
2. Set Search Path
3. Use Constraints
4. Monitor Performance
Next Steps
SQL Server Adapter
Setup for SQL Server databases
MySQL Adapter
Setup for MySQL and MariaDB
Teachables
Inject domain knowledge
API Reference
Full adapter API documentation