> ## Documentation Index
> Fetch the complete documentation index at: https://docs.b3os.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Database Query

Execute a SQL query against your organization's Postgres database. Supports SELECT, INSERT, UPDATE, and DELETE. Use parameterized queries with $1, $2, … placeholders. One statement per query — no semicolons.

Built-in action Built In

Execute a SQL query against your organization's Postgres database. Supports SELECT, INSERT, UPDATE, and DELETE. Use parameterized queries with $1, $2, … placeholders. One statement per query — no semicolons.


## At a Glance

| Field | Value |
| --- | --- |
| Action ID | `db-query` |
| Category | Built In |
| Connector | Not required |
| Requires gas | No |
| Funds movement | None declared |
| Tags | `database`, `sql`, `query`, `storage` |

## Payload Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `sql` | `string` | Yes | SQL statement to execute. Use $1, $2, … for parameter placeholders. |
| `params` | `array` | No | Values to bind to $1, $2, … placeholders in the SQL statement. Array values are supported for 'col = ANY\($n\)' filters: elements must all be one type — all strings, all numbers, all booleans, or all objects; mixed or null elements are rejected. Strings bind as text\[\], numbers as float8\[\]/int8\[\], booleans as bool\[\], objects as jsonb\[\]. Empty arrays bind as an untyped empty array whose type Postgres infers from the query context; an explicit placeholder cast \(e.g. '= ANY\($1::int\[\]\)'\) is never required but makes the intended type explicit. |

## Result Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `status` | `string` | No | - |
| `rows` | `array` | No | Rows returned by SELECT queries. |
| `rowsAffected` | `integer` | No | Number of rows affected by INSERT/UPDATE/DELETE. |

## Examples

**Workflow node**

```json
{
  "type": "db-query",
  "payload": {
    "sql": "SELECT * FROM users WHERE age > $1"
  },
  "children": []
}
```
  **Test with API**

```bash
curl -X POST "https://api.b3os.org/v1/actions/db-query/test" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "sql": "SELECT * FROM users WHERE age > $1"
  }
}'
```

**Use expressions for dynamic values**

Payload fields can use workflow expressions such as `{{$trigger.body.amount}}`, `{{$nodes.fetch.result.price}}`, and `{{$props.asset}}` when the value should come from a trigger, prior node, or reusable workflow prop.