Learn R Programming

taskqueue (version 0.2.0)

db_disconnect: Disconnect from PostgreSQL Database

Description

Safely closes a database connection. Checks if the connection is valid before attempting to disconnect.

Usage

db_disconnect(con)

Value

Invisibly returns NULL. Called for side effects.

Arguments

con

A connection object as produced by db_connect or DBI::dbConnect.

Details

This function wraps RPostgres::dbDisconnect() with a validity check to avoid errors when disconnecting an already-closed connection.

See Also

db_connect

Examples

Run this code
if (FALSE) {
# Not run:
# Connect and disconnect
con <- db_connect()
# ... perform database operations ...
db_disconnect(con)

# Safe to call on.exit to ensure cleanup
con <- db_connect()
on.exit(db_disconnect(con), add = TRUE)
}

Run the code above in your browser using DataLab