sql_create_table: Generate SQL CREATE TABLE statements

Description Usage Arguments Value Examples

View source: R/as_sql.R

Description

Creates SQL CREATE TABLE statements from a vector of column names and a vector of column types

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
sql_create_table(
  tname,
  col_name,
  col_type,
  col_opts = rep("", length(col_name)),
  const_name = NULL,
  const_type = NULL,
  const_cols = NULL,
  const_class = "constraint"
)

Arguments

tname

character scalar. Name of target sql table

col_name

character vector. Column names of target sql table

col_type

character scalar. Column types of target sql table. Columns of type NA will be skipped

col_opts

column options of target sql table (for example NOT NULL)

const_name

character vector. Name of the constraint.

const_type

character vector. Type of the constraint. Currently the only supported value is "PRIMARY KEY" but foreign keys will be supported in the future

const_cols

a list of character vectors that must be the same length as const_name. If each constraint only consists of a single column, const_cols may also be a character vector of the same length as const_name.

const_class

character vector. Either CONSTRAINT, PERIOD or RAW.

Value

a CREATE TABLE statement as a character scalar

Examples

1
2
3
4
5
6
sql_create_table(
  "example.table",
  c("numbers", "animals"),
  c("integer", "varchar(8)"),
  c("NOT NULL", "")
)

s-fleck/tabde documentation built on April 4, 2021, 10:11 p.m.