Flow reference: Storage & Databases
SQL Query
Run one SQL statement on your own PostgreSQL database, with values passed safely as $1, $2… parameters.
Run one SQL statement on your own PostgreSQL database, with values passed safely as $1, $2… parameters.
When and how to use it
Connect the input from the preceding step on the path that should perform this operation.
Fill the fields with data available in the trigger's context.
Connect the needed outputs; an unconnected path cannot run later blocks.
Configuration fields
Connection string — connection
A postgres://user:password@host:5432/database URL, kept in a bot env secret such as {env.DATABASE_URL} rather than typed into the block. The host must be reachable on the public internet; TLS is used unless the URL ends with ?sslmode=disable (?sslmode=verify-full also checks the certificate).
Input: Text with variable suggestions.
Editor guidance: postgres://user:password@host:5432/database. Keep it in an env secret, e.g. {env.DATABASE_URL}. The host must be public; TLS is used unless the URL says sslmode=disable.
Format example, not a ready value for your server:
{env.DATABASE_URL}.Default:
{env.DATABASE_URL}.SQL — sql
One SQL statement for your PostgreSQL. Put $1, $2… where values belong; {variables} written here are not filled in, which keeps member input out of the SQL text. A statement is stopped after 10 seconds.
Input: Multiline text.
Editor guidance: One statement. Write $1, $2… where values go; {variables} are never put into the SQL text. Times out after 10 s.
Format example, not a ready value for your server:
UPDATE members SET points = points + 1 WHERE discord_id = $1 RETURNING points.Default:
SELECT * FROM members WHERE discord_id = $1 LIMIT 10.Parameters (one per line: $1, $2…) — sqlParams
One value per line: line 1 becomes $1, line 2 becomes $2 (at most 20). Variables are filled in here and sent to the database as values, never as SQL.
Input: Multiline text.
Editor guidance: Line 1 is $1, line 2 is $2 and so on (max 20). Variables are filled in here and sent as values.
Format example, not a ready value for your server:
{user.id}.Default:
{user.id}.Store as — storeAs
Choose a short result prefix such as result. Later blocks must use this same prefix and run after this block. It is not a Discord channel or a persistent table.
Input: Text.
Editor guidance: {sql.count} rows, {sql.affected} changed rows, {sql.0.column} (or {sql.column} for the first row), {sql.rows} as JSON (first 100 rows), {sql.error} on failure.
Default:
sql.Outputs and next steps
out: Continue to the next step.failed: The operation failed; provide a safe error response.Read the result after this block, using its configured prefix and the fields supported by the selected operation. Do not assume every response has a text or id field.
Test and troubleshoot
Test a missing record, then save and read the same lookup value. Use a narrow filter for Update/Delete. Renaming a table or field changes where the lookup runs.
Save, validate and publish. Perform one real test and read the first relevant log error. [Testing](/docs/flow-testing) · [Variables](/docs/flow-variables) · [Permissions](/docs/flow-permissions).
Save, validate and publish. Perform one real test and read the first relevant log error. [Testing](/docs/flow-testing) · [Variables](/docs/flow-variables) · [Permissions](/docs/flow-permissions).