select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Unsupported versions: 7.3 / 7.2 / 7.1
Historical version. PostgreSQL 7.1 reached end of support in April 2006. See the current manual for supported releases.

query

Name

query -- executes a SQL command

Synopsis

query(command)

Parameters

command

SQL command (string).

Return Type

pgqueryobject or None

Result values.

Exceptions

TypeError

Bad argument type, or too many arguments.

ValueError

Empty SQL query.

pg.error

Error during query processing, or invalid connection.

Description

query() method sends a SQL query to the database. If the query is an insert statement, the return value is the OID of the newly inserted row. If it is otherwise a query that does not return a result (i.e., is not a some kind of SELECT statement), it returns None. Otherwise, it returns a pgqueryobject that can be accessed via the getresult() or dictresult() methods or simply printed.

Report a documentation issue

Read the upstream documentation. For corrections, first check the current manual.