dbBegin() starts a transaction. dbCommit() and dbRollback() end the transaction by either committing or rolling back the changes.

# S4 method for PqConnection
dbBegin(conn, ...)

# S4 method for PqConnection
dbCommit(conn, ...)

# S4 method for PqConnection
dbRollback(conn, ...)

Arguments

conn

a PqConnection object, produced by DBI::dbConnect()

...

Unused, for extensibility.

Value

A boolean, indicating success or failure.

Examples

# For running the examples on systems without PostgreSQL connection: run <- postgresHasDefault()
#> Could not initialise default postgres database. If postgres is running #> check that the environment variables PGHOST, PGPORT, #> PGUSER, PGPASSWORD, and PGDATABASE, are defined and #> point to your database.
library(DBI) if (run) con <- dbConnect(RPostgres::Postgres()) if (run) dbWriteTable(con, "USarrests", datasets::USArrests, temporary = TRUE) if (run) dbGetQuery(con, 'SELECT count(*) from "USarrests"') if (run) dbBegin(con) if (run) dbExecute(con, 'DELETE from "USarrests" WHERE "Murder" > 1') if (run) dbGetQuery(con, 'SELECT count(*) from "USarrests"') if (run) dbRollback(con) # Rolling back changes leads to original count if (run) dbGetQuery(con, 'SELECT count(*) from "USarrests"') if (run) dbRemoveTable(con, "USarrests") if (run) dbDisconnect(con)