PostgreSQL Integration
Superglue provides native support for PostgreSQL databases, allowing you to execute SQL queries directly within your workflows without setting up a separate integration.Connection Format
PostgreSQL connections are automatically detected when the URL starts withpostgres://
or postgresql://
.
Basic Connection Structure
Authentication
PostgreSQL credentials can be provided in multiple ways:1. Connection String
Include credentials directly in the URL:2. Using Variables
Use Superglue variables for secure credential management:3. SSL/TLS Configuration
The connection automatically uses SSL withrejectUnauthorized: false
for flexibility. For production environments with valid certificates, this can be configured accordingly.
Query Execution
Simple Queries
Basic query without parameters:Parameterized Queries (Recommended)
Parameterized queries prevent SQL injection and improve performance:Dynamic Parameters with Variables
Use Superglue variables and expressions in parameters:Insert Operations
Insert data with returning clause:params
and values
keys are supported for compatibility.
Workflow Examples
Example 1: Simple Data Retrieval
Example 2: Multi-Step Query with Dependencies
Example 3: Batch Insert with Loop
Common Patterns
1. Exploratory Queries
When you need to understand the database structure:2. Transactions (Single Statement)
PostgreSQL executes each query in its own transaction by default:3. JSON Operations
Working with JSONB columns:4. Date Filtering
Error Handling
The PostgreSQL integration includes automatic retry logic and comprehensive error reporting:- Connection errors: Check your connection string and network accessibility
- Authentication errors: Verify credentials and database permissions
- Query errors: Review SQL syntax and table/column names
- Timeout errors: Default timeout is 30 seconds, configurable via options
Common Issues
- Database name sanitization: Special characters in database names are automatically cleaned
- SSL connections: SSL is enabled by default with flexible certificate validation
- Parameter mismatches: Ensure the number of
$n
placeholders matches the params array length
Performance Considerations
- Use parameterized queries: Better performance and security than string concatenation
- Limit result sets: Add
LIMIT
clauses to prevent overwhelming data transfers - Index optimization: Ensure proper indexes exist for frequently queried columns
- Connection pooling: Each query creates a new connection pool that’s closed after execution
Security Best Practices
- Never hardcode credentials: Use Superglue’s variable system for sensitive data
- Always use parameterized queries: Prevents SQL injection attacks
- Principle of least privilege: Use database users with minimal required permissions
- Validate input data: Sanitize data before using in queries, even with parameters
- Use read-only users: For data retrieval workflows, use accounts without write permissions
Response Format
PostgreSQL queries return an array of row objects:[]
.