drop_schema: Drop a Postgres schema

Description Usage Arguments See Also Examples

View source: R/drop.R

Description

Drop a schema if it exists.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
drop_schema(
  conn,
  conn_fun,
  schema,
  cascade = FALSE,
  if_exists = TRUE,
  verbose = TRUE,
  render_sql = TRUE,
  render_only = FALSE,
  ...
)

Arguments

...

Additional arguments passed to the DatabaseConnector::dbSendStatement function

See Also

Other schema functions: create_schema(), drop_cascade(), drop_if_exists()

Other drop functions: drop_all_staging_tables(), drop_cascade(), drop_if_exists(), drop_table_batch(), drop_table()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(pg13)
create_test_schema <-
        function(conn) {

                if (!schema_exists(conn = conn,
                                   schema = "test_schema")) {

                        cli::cli_rule("Create 'test_schema' Schema")

                        create_schema(conn = conn,
                                      schema = "test_schema")

                }
        }


conn <- local_connect(dbname = "pg13_test")
create_test_schema(conn = conn)
write_table(conn = conn,
            schema = "test_schema",
            table_name = "test_table",
            drop_existing = TRUE,
            data = data.frame(A = 1:3, B = letters[1:3]))

write_table(conn = conn,
            schema = "test_schema",
            table_name = "test_table2",
            drop_existing = TRUE,
            data = data.frame(C = rep(NA, 3), D = c(TRUE, FALSE, FALSE)))

write_table(conn = conn,
            schema = "test_schema",
            table_name = "test_table3",
            drop_existing = TRUE,
            data = data.frame(E = c(1.25, 343.31341, 5),
                              G = c(Sys.Date(), Sys.Date()-100, Sys.Date()-1000)))

drop_schema(conn = conn,
            schema = "test_schema",
            cascade = TRUE)

dc(conn = conn)

patelm9/pg13 documentation built on Dec. 26, 2021, 8:17 p.m.