CLOSE(7)

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

πŸ’… CLOSE(7) β€” the PostgreSQL glow-up

okay bestie, welcome to CLOSE, page 7 of the PostgreSQL 15.19 docs ✨ this is the one where we say bye-bye to a cursor, and honestly? it's giving closure (literally). let's get into it 🫢


🌸 SYNOPSIS

CLOSE { name | ALL }

that's it. that's the whole vibe check. two ways to do it, pick your fighter πŸ’…


✨ DESCRIPTION

CLOSE frees the resources associated with an open cursor πŸ”₯ after the cursor is closed, no subsequent operations are allowed on it β€” like, none, bestie, it's done πŸ’€ a cursor should be closed when it is no longer needed.

here's the lore on when cursors get closed automatically, no cap:

  • 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
  • but if the creating transaction successfully commits, the holdable cursor remains open until an explicit CLOSE is executed, or the client disconnects 🌈

so like, holdable cursors have main character energy and stick around. noted. πŸ™ˆ


πŸŽ€ PARAMETERS

  • name β€” the name of an open cursor to close. just the one. your fave. πŸ’–
  • ALL β€” close all open cursors. every single one. goodbye to the whole group chat πŸ‘‹

πŸ¦‹ NOTES

okay so here's a thing that trips people up: 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. that's the whole opening ceremony, iykyk ✨

you can see all available cursors by querying the pg_cursors system view πŸ‘€ highly recommend, it's literally the cursor group photo.

and now the caveat, listen up πŸ”₯:

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. periodt. πŸ’…

πŸ’œ EXAMPLES

close the cursor liahona:

CLOSE liahona;

slay. that cursor is gone. πŸŽ€


⭐ COMPATIBILITY

CLOSE is fully conforming with the SQL standard βœ… CLOSE ALL is a PostgreSQL extension 🌸 (yes, we added that ourselves, you're welcome πŸ’…)


πŸ‘‘ SEE ALSO

DECLARE(7), FETCH(7), MOVE(7) β€” go read those next, bestie, they're iconic 🫢


mwah πŸ’‹ that was CLOSE(7) from the PostgreSQL 15.19 docs, dated 2026 β€” go forth and close your cursors responsibly, ily 🌈✨

πŸ“¦ where this page comes from