Query Database
Query your own external database (postgres, mysql, supabase, etc.)
The Query Database block allows your AI Agent to connect to and query an external SQL database during runtime. It supports PostgreSQL, MySQL, and Microsoft SQL Server, making it ideal for workflows that require live data access — such as retrieving customer records, product inventory, or historical logs.
Configurations
Account
Connect the database account your agent will use to run queries.
You can choose:
Static Account: A fixed database connection defined at build time.
Dynamic (Ask at Runtime): Prompts the user to input database credentials during execution.
To connect, select your database type (PostgreSQL, MySQL, etc.) and enter:
Host
db.abcd.supabase.co
Port
5432
Database
postgres
Username
postgres
Password
YOUR SECRET KEY
Query
Enter the SQL query to run against the external database. You can use dynamic variables with {{brackets}}
to inject content from earlier in the workflow.
Example (Static Query):
SELECT * FROM users WHERE last_name = 'Williams';
Example (Dynamic Query using variable):
SELECT * FROM users WHERE last_name = '{{last_name}}';
Output Format
Choose how the result should be returned. Options include:
JSON (default): Structured data ideal for parsing or display.
CSV: Comma-separated values, useful for exporting to spreadsheets or displaying flat tabular data.
Output Variable
Set a variable name to store the query result. This variable can be used in later blocks to display results or make decisions.
Example:
query_result
How It Works
The block connects to the selected external database using the provided credentials.
The SQL query is executed (with variables substituted if used).
The result is returned in your chosen format and stored in the specified output variable.
The next block in your workflow can use this result to generate responses, make decisions, or display information.
Last updated