Connect a database: connecting PostgreSQL, querying it from a workflow and filling a dropdown from it (1:28).

Connect a database
Let Triggr in
Start a connection

Paste the connection string
postgresql://user:password@host:5432/database?sslmode=require and click Continue.
Check the details

Test it
Query it from a workflow
Add Execute SQL from Database, choose the database and replace the example query in SQL Query with yours; this one finds yesterday’s failed backups in abackup_results table.

data, every value as text (empty for NULL).
ctx.steps['Find Failed Backups'].data, or read one value with {{ ctx.steps['Find Failed Backups'].data[0].client }}. A single row with a column named count, sum, avg, min, max or total also arrives as a number in value.
Change data
INSERT, UPDATE and DELETE work too; add RETURNING id to get the new rows back in data. Create tables with your own database tool. Each query has 30 seconds.
Put values in a query
Templates become part of the SQL text, so quote text values and only use values you trust:O'Brien, breaks the query and could change what it does. For anything a person or another system typed, double the apostrophes in a Code step first, as the Evaluate step does in the uptime monitor.
Use it in forms
A Select field can list options from your database: set Options Source to Use database, choose the connection and write a query that returns a value column and a label column.{{ ctx.client.variableName }} inserts a client variable of the person’s client. Test Query runs the query as typed, so test it without templates first.

Security
Triggr stores the password encrypted, and every Execute SQL step runs as the database user you entered, whoever runs the workflow. Anyone with the Admin role can edit connections and write queries against them.Troubleshooting
“failed to connect to database: dial tcp: lookup … no such host”
“failed to connect to database: dial tcp: lookup … no such host”

Test Connection waits, then fails with a timeout or “connection refused”
Test Connection waits, then fails with a timeout or “connection refused”
“pq: password authentication failed for user …”
“pq: password authentication failed for user …”
@ encoded.“pq: SSL is not enabled on the server”
“pq: SSL is not enabled on the server”
“SQL query failed: invalid SQL query: …”
“SQL query failed: invalid SQL query: …”
CREATE TABLE, or a connection error like those above.
“Invalid connection string format. Please check and try again.”
“Invalid connection string format. Please check and try again.”
postgresql://user:password@host:5432/database, or choose Manual Setup and type the details.Which databases can I connect?
Which databases can I connect?

