# NOT RUN {
library(DBI)
con <- dbConnect(RPostgres::Postgres())
dbWriteTable(con, "USarrests", datasets::USArrests, temporary = TRUE)
dbGetQuery(con, 'SELECT count(*) from "USarrests"')
dbBegin(con)
dbExecute(con, 'DELETE from "USarrests" WHERE "Murder" > 1')
dbGetQuery(con, 'SELECT count(*) from "USarrests"')
dbRollback(con)
# Rolling back changes leads to original count
dbGetQuery(con, 'SELECT count(*) from "USarrests"')
dbRemoveTable(con, "USarrests")
dbDisconnect(con)
# }
Run the code above in your browser using DataLab