Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sql.postgres.statement

import sql.postgres.statement

sql lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled sql.postgres.statement.* needs import sql.postgres.statement.

A PostgreSQL statement compiled once and run many times.

Every statement this adapter runs is compiled on the server, so a prepared statement is not doing anything a plain query does not. The difference is ownership: this one has a name of its own and is released when the program says so, rather than living in the connection’s cache and being evicted when the cache fills.

Classes

PostgresStatement

class sql.postgres.PostgresStatement < DriverStatement

A compiled PostgreSQL statement.

  • printable — has a @to_string(), so echo and print() show something useful

Constructor

sql.postgres.PostgresStatement(connection, compiled)

Parameters

  • connection (PostgresConnection)
  • compiled (dict) — name, sql, parameters and columns as the server described them.

PostgresStatement.columns()

sql.postgres.PostgresStatement.columns()

PostgresStatement.parameter_count()

sql.postgres.PostgresStatement.parameter_count()

PostgresStatement.execute()

sql.postgres.PostgresStatement.execute(values: list) -> dict

Runs the statement for its effect.

Parameters

  • values (list)

Returns dict — { rows_affected, last_insert_id }

PostgresStatement.select()

sql.postgres.PostgresStatement.select(values: list) -> dict

Runs the statement and reads its whole result.

Parameters

  • values (list)

Returns dict — { columns, rows }

PostgresStatement.open_cursor()

sql.postgres.PostgresStatement.open_cursor(values: list, options: dict) -> PostgresCursor

Runs the statement and hands back a cursor over its result.

Parameters

  • values (list)
  • options (dict) — { batch }

Returns PostgresCursor

PostgresStatement.close()

sql.postgres.PostgresStatement.close()

Releases the statement on the server. Safe to call more than once.

PostgresStatement.is_closed()

sql.postgres.PostgresStatement.is_closed() -> bool

Whether this statement has been closed.

Returns bool

PostgresStatement.to_string()

sql.postgres.PostgresStatement.to_string()

2026, Richard Ore and Zuri contributors