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.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
- The API runs your query against the database with security guardrails
- The results are returned as an array of objects
Code Examples
Example: Basic SQL Query
This example shows how to execute a simple SQL query to retrieve active users.Example: Advanced SQL Query
This example shows how to execute a more complex SQL query with aggregations.Request Body Explained
The SQL query to execute against the database. This can be any valid SQL query that reads data (SELECT statements).For security reasons, certain operations may be restricted to prevent accidental data loss or unauthorized access.
Response 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 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