Skip to main content

Postgres / SQL

Connects to a PostgreSQL database via pgx. An agent can run read-only SELECT queries, execute write/DDL statements, describe a table's columns, and list tables in a schema.

Add to an agent node's tools array with _node_type: "tool-sql" (alias tool-postgres). See Connector Reference — How connectors are used.

Authentication

FieldRequiredDescription
dsnYes*PostgreSQL connection string, e.g. postgres://user:pass@host:5432/db.
connection_stringYes*Fallback for dsn — used only if dsn is empty.

* One of dsn or connection_string must be set; otherwise the connector returns an error.

{
"name": "postgres",
"_node_type": "tool-sql",
"dsn": "{{ secret.POSTGRES_DSN }}"
}

tool-postgres is accepted as an equivalent _node_type for the same connector.

Tools

sql_query

Run a SELECT query against PostgreSQL and return results as a formatted table.

Parameters

ParameterTypeRequiredDescription
querystringYesSELECT query to run
max_rowsnumberNoMaximum rows to return (default 100, hard cap 500)

Returns: A tab-separated table: a header row of column names, a separator line, then up to max_rows data rows (each value formatted with %v), followed by a ... (truncated at N rows) line if truncated, and a final N row(s) count line.

sql_execute

Execute a SQL statement (INSERT, UPDATE, DELETE, CREATE, ALTER). Returns rows affected.

Parameters

ParameterTypeRequiredDescription
statementstringYesINSERT UPDATE DELETE or DDL statement

Returns: OK — N rows affected.

sql_describe_table

Describe a table's columns, types, nullability and defaults.

Parameters

ParameterTypeRequiredDescription
tablestringYesTable name to describe
schemastringNoSchema name (default: public)

Returns: A tab-separated table with header column\ttype\tnullable\tdefault, a separator line, then one row per column (queried from information_schema.columns).

sql_list_tables

List all tables in a PostgreSQL schema.

Parameters

ParameterTypeRequiredDescription
schemastringNoSchema to list (default: public)

Returns: Tables in <schema>: followed by one line per table, formatted as <name padded to 40 chars> <table_type> (queried from information_schema.tables).

Next