CLOSE(7)

πŸ“¦ version 16.15, in opensuse-leap 16.0

✨ CLOSE(7) ✨

okay so bestie, we're talking about the PostgreSQL 16.15 manual page for CLOSE β€” literally the "bye bye cursor" command and honestly? it's giving closure in the most literal sense πŸ’…


πŸŽ€ NAME πŸŽ€

CLOSE β€” close a cursor 🌸


πŸ¦‹ SYNOPSIS πŸ¦‹

CLOSE { name | ALL }

πŸ’– DESCRIPTION πŸ’–

so CLOSE frees the resources associated with an open cursor, periodt. Once the cursor is closed, no subsequent operations are allowed on it β€” like, it's done, it's not coming back, the vibe check failed and it's out 🫢. 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. Meanwhile a holdable cursor gets implicitly closed if the transaction that created it aborts via ROLLBACK. But β€” and this is the main character plot twist β€” if the creating transaction successfully commits, that holdable cursor remains open until an explicit CLOSE is executed, or the client disconnects. so yeah, it just chills there πŸ‘‘


⭐ PARAMETERS ⭐

  • name β€” the name of an open cursor to close πŸŽ€
  • ALL β€” close all open cursors. every single one. no survivors πŸ’€

🌈 NOTES 🌈

PostgreSQL does not have an explicit OPEN cursor statement β€” ngl that surprises everyone. A cursor is considered open when it is declared. So use the DECLARE statement to declare a cursor πŸ’–

You can see all available cursors by querying the pg_cursors system view β€” lowkey the best way to keep tabs on your cursor squad πŸ‘‘

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. like, that close is permanent fr fr, no take-backs πŸ™ˆ

πŸ“ EXAMPLES πŸ“

Close the cursor liahona:

CLOSE liahona;

slay, liahona is free πŸ•ŠοΈ


🧚 COMPATIBILITY 🧚

CLOSE is fully conforming with the SQL standard ✨ (iconic behaviour, no notes). CLOSE ALL is a PostgreSQL extension β€” a little extra, and we love that for us πŸ’…


πŸ‘‘ SEE ALSO πŸ‘‘

DECLARE(7), FETCH(7), MOVE(7) β€” go read those too bestie, they're the whole cursor friend group 🫢


and that's the page!! brought to you by PostgreSQL 16.15, dated 2026 β€” mwah, drink water, close your cursors, ily πŸ’œβœ¨

πŸ“¦ where this page comes from