CLOSE
close a cursor
English manual coverage begins with PostgreSQL 6.4. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- anchor
- SQL-CLOSE
- file
- sql-close.html
- lang
- en
- name
- CLOSE
- purpose
- close a cursor
- purpose zh
- 关闭一个游标
- sections same as
- Unknown
- slug
- 18
- synopsis html
- CLOSE { <em class="replaceable"><code>name</code></em> | ALL }
- synopsis text
- CLOSE { name | ALL }
Syntax
CLOSE { name | ALL }Syntax diagrams
Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.
Definition PG 18
CLOSE { name | ALL }Description
CLOSE frees the resources associated with an open cursor. After the cursor is closed, no subsequent operations are allowed on it. A cursor should be closed when it is no longer needed.
Every non-holdable open cursor is implicitly closed when a transaction is terminated by COMMIT or ROLLBACK. A holdable cursor is implicitly closed if the transaction that created it aborts via ROLLBACK. If the creating transaction successfully commits, the holdable cursor remains open until an explicit CLOSE is executed, or the client disconnects.
Parameters
nameThe name of an open cursor to close.
ALLClose all open cursors.
Notes
PostgreSQL does not have an explicit OPEN cursor statement; a cursor is considered open when it is declared. Use the DECLARE statement to declare a cursor.
You can see all available cursors by querying the pg_cursors system view.
If a cursor is closed after a savepoint which is later rolled back, the CLOSE is not rolled back; that is, the cursor remains closed.
Examples
Close the cursor liahona:
CLOSE liahona;
Compatibility
CLOSE is fully conforming with the SQL standard. CLOSE ALL is a PostgreSQL extension.
See Also
DECLARE, FETCH, MOVECompare versions
Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · wiki-repair-20261023:1f9e42727c93aea298044aead9b907635176b9bb6e836894465aadffa79bb75d
Text language: en · wiki-repair-20261023:1f9e42727c93aea298044aead9b907635176b9bb6e836894465aadffa79bb75d