Exposes interface to simple CREATE TABLE commands. The default method is ANSI SQL 99 compliant. This method is mostly useful for backend implementers.

sqlCreateTable(con, table, fields, row.names = NA, temporary = FALSE, ...)

Arguments

con

A database connection.

table

Name of the table. Escaped with dbQuoteIdentifier().

fields

Either a character vector or a data frame.

A named character vector: Names are column names, values are types. Names are escaped with dbQuoteIdentifier(). Field types are unescaped.

A data frame: field types are generated using dbDataType().

row.names

Either TRUE, FALSE, NA or a string.

If TRUE, always translate row names to a column called "row_names". If FALSE, never translate row names. If NA, translate rownames only if they're a character vector.

A string is equivalent to TRUE, but allows you to override the default name.

For backward compatibility, NULL is equivalent to FALSE.

temporary

If TRUE, will generate a temporary table statement.

...

Other arguments used by individual methods.

DBI-backends

If you implement one method (i.e. for strings or data frames), you need to implement both, otherwise the S4 dispatch rules will be ambiguous and will generate an error on every call.

Examples

sqlCreateTable(ANSI(), "my-table", c(a = "integer", b = "text"))
#> <SQL> CREATE TABLE "my-table" ( #> "a" integer, #> "b" text #> ) #>
sqlCreateTable(ANSI(), "my-table", iris)
#> <SQL> CREATE TABLE "my-table" ( #> "Sepal.Length" DOUBLE, #> "Sepal.Width" DOUBLE, #> "Petal.Length" DOUBLE, #> "Petal.Width" DOUBLE, #> "Species" TEXT #> ) #>
# By default, character row names are converted to a row_names colum sqlCreateTable(ANSI(), "mtcars", mtcars[, 1:5])
#> <SQL> CREATE TABLE "mtcars" ( #> "row_names" TEXT, #> "mpg" DOUBLE, #> "cyl" DOUBLE, #> "disp" DOUBLE, #> "hp" DOUBLE, #> "drat" DOUBLE #> ) #>
sqlCreateTable(ANSI(), "mtcars", mtcars[, 1:5], row.names = FALSE)
#> <SQL> CREATE TABLE "mtcars" ( #> "mpg" DOUBLE, #> "cyl" DOUBLE, #> "disp" DOUBLE, #> "hp" DOUBLE, #> "drat" DOUBLE #> ) #>