Query External SQL Database
The Query External SQL Database block runs a SQL query against a database connection that has been configured in the workspace.
Execute SQL queries against external databases
The Query External SQL Database block runs a SQL query against a database connection that has been configured in the workspace. It targets a specific connection by ID, accepts any SQL query string as input, and returns the results either as a JSON array of row objects or as a CSV-formatted string, depending on the output format you select. The result is stored in a variable you define, making it available to downstream blocks in the workflow.
The block has four main configuration fields: the connection ID pointing to a workspace-level database connection, the SQL query to execute, the destination variable name where results will be stored, and the output format toggle between JSON and CSV. The output field exposes a data property containing the query results — an array of objects when JSON is selected, or a plain CSV string when CSV is selected.
This block fits into workflows that need to read or write structured data from an external database as part of a larger AI-driven process. Common patterns include fetching records to provide context for an AI prompt, retrieving user-specific data based on earlier inputs, or writing query results to a report or downstream processing step.
What you can build
Real-world workflows powered by the Query External SQL Database block.
AI Prompt Context Lookup
Query a product or knowledge database to retrieve relevant records, then pass those results directly into an AI prompt block as grounding context.
User Data Personalization
Fetch user-specific records from a connected database based on an identifier collected earlier in the workflow, enabling personalized AI responses.
Automated Report Generation
Pull aggregated data from a SQL database and format the results as CSV for export or further processing in a reporting workflow.
CRM Record Retrieval
Query a MySQL or PostgreSQL CRM database to surface customer history or account details during an AI-assisted support or sales workflow.
Dynamic Content Population
Retrieve rows from a content or inventory database to dynamically populate templates or AI-generated documents with up-to-date information.
Data Validation Checks
Run a SQL query to verify whether a submitted value exists in the database before allowing a workflow to proceed to the next step.
Ready to add Query External SQL Database to your workflow?
Get Started FreeCommon questions about Query External SQL Database
What parameters are required to use this block?
The block requires a database connection ID referencing a connection configured at the workspace level, and a SQL query string to execute. The destination variable name and output format (JSON or CSV) are also configurable, with output format being a required selection between the two options.
What does the block return?
The block returns a data field containing the query results. When the output format is set to JSON, data is an array of objects where each object represents a row. When set to CSV, data is a single CSV-formatted string.
Which database types are supported?
The block supports PostgreSQL (including Supabase-hosted PostgreSQL), MySQL, and MSSQL databases, provided the connection has been set up in the workspace beforehand.
What kinds of workflows commonly use this block?
This block is commonly used in workflows that need to retrieve structured data to inform AI prompts, personalize responses based on user records, generate reports from live database data, or validate inputs against existing database entries.
Where is the query result stored after execution?
The result is stored in the variable name specified in the destinationVar field. That variable is then accessible to subsequent blocks in the workflow.
Related capabilities
Query Data Source
Search a vector data source (RAG) and return relevant document chunks.
Create Data Source
Create a new empty vector data source for the current app.
Delete Data Source
Delete a vector data source from the current app.
Upload Data Source Document
Upload a file into an existing data source from a URL or raw text content.
List Data Sources
List all data sources for the current app.
Delete Data Source Document
Delete a single document from a data source.
Add Query External SQL Database to your workflow
Build powerful AI workflows with drag-and-drop blocks. No coding required.