Postgresql 中文操作指南

CLOSE

CLOSE — 关闭游标

CLOSE — close a cursor

Synopsis

CLOSE { name | ALL }

Description

CLOSE 释放与打开游标关联的资源。在关闭游标后,不允许对它执行后续操作。游标在不再需要时应被关闭。

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.

当事务终止于 COMMITROLLBACK 时,每个不可保持打开游标都将隐式关闭。当创建游标的事务通过 ROLLBACK 中止时,该游标将隐式关闭。如果创建事务成功提交,则可保持游标打开状态,直至执行 CLOSE ,或客户端断开连接。

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

  • name

    • The name of an open cursor to close.

  • ALL

    • Close all open cursors.

Notes

PostgreSQL 没有显式的 OPEN 游标声明;在声明游标时,游标将被视为打开。使用 DECLARE 语句声明游标。

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.

你可以通过查询 pg_cursors 系统视图来查看所有可用的游标。

You can see all available cursors by querying the pg_cursors system view.

如果游标在某个保存点之后关闭,并且该保存点随后进行回滚,则 CLOSE 不会回滚,即游标保持关闭状态。

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

关闭游标 liahona

Close the cursor liahona:

CLOSE liahona;

Compatibility

CLOSE 完全符合 SQL 标准。 CLOSE ALL 是 PostgreSQL 的扩展。

CLOSE is fully conforming with the SQL standard. CLOSE ALL is a PostgreSQL extension.

See Also