Description Usage Arguments See Also Examples
Draft a SQL that creates a table using DDL derived from a dataframe. Drafting is stopped if the given tablename or fields in the dataframe are a SQL reserve word.
1 | draft_create_table(schema, table_name, if_not_exists = TRUE, ...)
|
... |
Named vector of field names and their corresponding data definition. |
Other create functions:
create_schema()
,
create_table_from_df()
,
create_table()
,
draft_create_table_from_df()
Other draft functions:
draft_base()
,
draft_create_table_from_df()
,
draft_in()
,
draft_join()
,
draft_limit()
,
draft_random()
,
draft_table_path()
,
draft_where_in()
,
draft_where_like()
,
draft_where_lower_in()
,
draft_where_lower_like()
,
draft_where_lower_not_in()
,
draft_where_not_in()
,
paste_wheres()
,
table.path()
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | library(pg13)
create_test_schema <-
function(conn) {
if (!schema_exists(conn = conn,
schema = "test_schema")) {
create_schema(conn = conn,
schema = "test_schema")
}
}
conn <- local_connect(dbname = "pg13_test")
create_test_schema(conn = conn)
# Write a table
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 the same table using create_table() instead
create_table(conn = conn,
schema = "test_schema",
table_name = "test_table_b",
if_not_exists = TRUE,
A = "integer",
B = "varchar(1)")
append_table(conn = conn,
schema = "test_schema",
table = "test_table_b",
data = data.frame(A = 1:3, B = letters[1:3]))
# Under the hood is the draft_create_table()
draft_create_table(schema = "test_schema",
table_name = "test_table_b",
A = "integer",
B = "varchar(1)")
# The DDL can be automatically discerned using create_table_from_df()
create_table_from_df(conn = conn,
schema = "test_schema",
table_name = "test_table_c",
data = data.frame(A = 1:3, B = letters[1:3]))
# Under the hood is the draft_create_table_from_df()
draft_create_table_from_df(schema = "test_schema",
table_name = "test_table_c",
data = data.frame(A = 1:3, B = letters[1:3]))
drop_schema(conn = conn,
schema = "test_schema",
cascade = TRUE)
dc(conn = conn)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.