> ## 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

> Executing one parameterized SQL statement, including reads, mutations, and DDL, against a connected Postgres database. Postgres Run Query reference includes.

Executing one parameterized SQL statement, including reads, mutations, and DDL, against a connected Postgres database.

<Info>
  Tool ID: `postgres_run_query`
</Info>

## Run this action

Use the TypeScript SDK for a single call. Put `ctx.tools.execute(...)` inside a Play when the call should be durable, scheduled, or run across a CSV.

```ts theme={null}
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={null}
deepline tools execute postgres_run_query --input '{
  "query": "software companies hiring engineers"
}' --json
```

## Example response

The SDK exposes this shape at `result.toolResponse.raw`. Values below are representative.

```json theme={null}
{
  "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 tools get 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={null}
  {
    "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={null}
  {
    "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](/docs/providers/postgres/guide)
* [SDK V2 quickstart](/docs/sdk-v2/quickstart)
* [SDK reference](/docs/sdk-v2/sdk-reference)
* [Run tools across a CSV](/docs/sdk-v2/batch-csv)
