What Does This Endpoint Do?
This endpoint allows you to execute SQL queries directly against your database. Think of it like having direct access to your database through SQL, but with safety measures in place to prevent accidental data loss or destructive operations. You can use both named parameters ({param}) and positional parameters ($1, $2) to safely pass values into your queries, preventing SQL injection attacks.
When to Use SQL Queries
You’ll find this endpoint useful when you need to:- Run complex queries: Perform advanced data analysis with SQL
- Generate reports: Create custom reports with aggregations and calculations
- Fetch specific data: Retrieve exactly what you need with precise SQL queries
- Run analytical queries: Perform calculations and aggregations on your data
- Use SQL functions: Leverage SQL’s built-in functions for data manipulation
- Perform bulk operations: Execute operations on multiple records efficiently
How It Works
- You provide a SQL query to execute (with optional parameters)
- You can use named parameters ({param}) or positional parameters ($1, $2) for safe value substitution
- The API runs your query against the database with security guardrails
- The results are returned as an array of objects
Code Examples
Example 1: Basic SQL Query with Named Parameters
This example shows how to execute a simple SQL query using named parameters to safely pass values.- Node.js
- Python
- Go
- cURL
Example 2: Advanced SQL Query with Positional Parameters
This example shows how to execute a more complex SQL query using positional parameters for safe value substitution.- Node.js
- Python
- Go
- cURL
Example 3: Mixed Parameter Types
This example shows how to use both named and positional parameters in the same query for maximum flexibility.- Node.js
- Python
- cURL
Request Body Explained
The SQL query to execute against the database. This can be any valid SQL query that reads data (SELECT statements).You can use either:
- Named parameters: {param}syntax (e.g.,SELECT * FROM users WHERE status = {status})
- Positional parameters: $1, $2, $3syntax (e.g.,SELECT * FROM users WHERE status = $1)
Parameters to safely substitute into your SQL query. Choose one format:For named parameters (For positional parameters (
{param} syntax): Provide an object with key-value pairs.$1, $2 syntax): Provide an array of values in order.The environment to query (development, staging, production). Defaults to production if not specified.Options: 
development, staging, productionResponse Fields Explained
true if the query was executed successfully, false otherwise.An array of objects containing the query results. Each object represents a row in the result set, with properties corresponding to the columns in your query.
The SQL query that was executed. This is useful for debugging and audit purposes.
The time taken to execute the query in milliseconds. This can help you optimize slow queries.
Example Response
Common Errors and How to Fix Them
| Error | Cause | Solution | 
|---|---|---|
| ”Table not found” | The specified table doesn’t exist | Check your table name for typos | 
| ”Syntax error in SQL query” | The SQL query contains syntax errors | Review your SQL syntax and fix any errors | 
| ”Operation not allowed” | You’re trying to perform a restricted operation | Use only allowed operations (typically SELECT statements) | 
| “Query timeout” | The query took too long to execute | Optimize your query or add more specific conditions | 
| ”Unauthorized” | Invalid or missing API key | Check that you’re using a valid API key | 
Tips for Successful Queries
- Use parameters for all dynamic values to prevent SQL injection attacks
- Choose the right parameter type: Use named parameters for readability, positional for performance
- Use LIMIT clauses to restrict the number of results returned
- Be specific with your SELECT columns rather than using SELECT *
- Add appropriate WHERE clauses to filter results
- Use indexes when querying large tables
- Test complex queries on small datasets first
- Consider query performance for production applications
Parameter Safety
Both named ({param}) and positional ($1, $2) parameters provide protection against SQL injection by properly escaping values. Choose the approach that best fits your use case:
- Named parameters: More readable and maintainable for complex queries
- Positional parameters: Slightly more performant for simple queries with few parameters
- Mixed usage: You can use both types in the same query for maximum flexibility

