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

# Postgres: Run Query

> Run one SQL statement, including reads, writes and schema changes, on the connected Postgres database. Includes SDK V2 examples, schemas, and cost.

Run one SQL statement, including reads, writes and schema changes, on the connected Postgres database.

> [!NOTE]
>
> Tool ID: `postgres_run_query`

## Run this action

Use the TypeScript SDK for one call. Use `ctx.tools.execute(...)` inside a Play for durable calls, scheduled calls, or CSV processing.

```ts theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
import { Deepline } from 'deepline';

const deepline = await Deepline.connect();
const result = await deepline.tools.execute(
  'postgres_run_query',
  {
    "query": "software companies hiring engineers"
  },
);

console.log(result.toolResponse.raw);
```

### CLI

```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
deepline tools execute postgres_run_query --input '{
  "query": "software companies hiring engineers"
}' --json
```

## Example response

The SDK returns this shape at `result.toolResponse.raw`. The example values illustrate the response.

```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
{
  "data": {
    "rows": [
      {}
    ],
    "rowCount": 123,
    "limited": true,
    "columns": [
      "example"
    ],
    "command": "example"
  },
  "meta": {
    "host": "api.example.com",
    "database": "example",
    "schema": "example",
    "rowLimit": 123,
    "timeoutMs": 123
  }
}
```

Use `deepline describe postgres_run_query --json` for the latest machine-readable contract.

## Input reference

Execute one parameterized SQL statement against the connected Postgres database. The database user controls permissions.

| Name | Type | Required | Default | Details |
| - | - | - | - | - |
| `payload.query` | `string` | Yes | — | One SQL statement. Mutating and DDL statements execute directly using the connected database user and may change customer data. |
| `payload.binds` | `array` | No | — | Positional values for numbered Postgres SQL parameters. |
| `payload.timeoutMs` | `integer` | No | `120000` | Minimum: 1000. Maximum: 600000. |
| `payload.rowLimit` | `integer` | No | `5000` | Minimum: 1. Maximum: 100000. |

<details>
  <summary>Show raw input schema</summary>

  ### Input JSON Schema

  ```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
  {
    "type": "object",
    "description": "Execute one parameterized SQL statement against the connected Postgres database. The database user controls permissions.",
    "properties": {
      "query": {
        "type": "string",
        "description": "One SQL statement. Mutating and DDL statements execute directly using the connected database user and may change customer data."
      },
      "binds": {
        "type": "array",
        "description": "Positional values for numbered Postgres SQL parameters.",
        "items": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "number"
            },
            {
              "type": "boolean"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "timeoutMs": {
        "type": "integer",
        "default": 120000,
        "minimum": 1000,
        "maximum": 600000
      },
      "rowLimit": {
        "type": "integer",
        "default": 5000,
        "minimum": 1,
        "maximum": 100000
      }
    },
    "required": [
      "query"
    ],
    "additionalProperties": false
  }
  ```
</details>

## Output reference

Postgres query result.

| Name | Type | Required | Default | Details |
| - | - | - | - | - |
| `result.data` | `object` | Yes | — | — |
| `result.data.rows` | `array` | Yes | — | — |
| `result.data.rowCount` | `integer` | Yes | — | — |
| `result.data.limited` | `boolean` | Yes | — | — |
| `result.data.columns` | `array` | Yes | — | — |
| `result.data.command` | `string` | Yes | — | — |
| `result.meta` | `object` | Yes | — | — |
| `result.meta.host` | `string` | Yes | — | — |
| `result.meta.database` | `string` | Yes | — | — |
| `result.meta.schema` | `string` | Yes | — | — |
| `result.meta.rowLimit` | `integer` | Yes | — | — |
| `result.meta.timeoutMs` | `integer` | Yes | — | — |

<details>
  <summary>Show raw output schema</summary>

  ### Output JSON Schema

  ```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
  {
    "type": "object",
    "description": "Postgres query result.",
    "properties": {
      "data": {
        "type": "object",
        "properties": {
          "rows": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": {}
            }
          },
          "rowCount": {
            "type": "integer"
          },
          "limited": {
            "type": "boolean"
          },
          "columns": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "command": {
            "type": "string"
          }
        },
        "required": [
          "rows",
          "rowCount",
          "limited",
          "columns",
          "command"
        ],
        "additionalProperties": false
      },
      "meta": {
        "type": "object",
        "properties": {
          "host": {
            "type": "string"
          },
          "database": {
            "type": "string"
          },
          "schema": {
            "type": "string"
          },
          "rowLimit": {
            "type": "integer"
          },
          "timeoutMs": {
            "type": "integer"
          }
        },
        "required": [
          "host",
          "database",
          "schema",
          "rowLimit",
          "timeoutMs"
        ],
        "additionalProperties": false
      }
    },
    "required": [
      "data",
      "meta"
    ],
    "additionalProperties": false
  }
  ```
</details>

## Deepline cost

* Pricing model: `fixed` (per call).
* Estimated Deepline credits: `0` per pricing unit.
* Provider-native pricing may still exist outside Deepline credit billing.

## Related documentation

* [Postgres provider guide](https://deepline.com/docs/providers/postgres/guide.md)
* [SDK V2 quickstart](https://deepline.com/docs/sdk-v2/quickstart.md)
* [SDK reference](https://deepline.com/docs/sdk-v2/sdk-reference.md)
* [Run tools across a CSV](https://deepline.com/docs/sdk-v2/batch-csv.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.