get_sql_create: Generate SQL to CREATE TABLE

View source: R/get_sql_create.R

get_sql_createR Documentation

Generate SQL to CREATE TABLE

Description

This function uses the output from nchar_df() to generate a SQL CREATE TABLE statement that can be used to create the skeleton table in Postgres. The result can be copied and pasted for use.

Usage

get_sql_create(pg_fields, schema = "public", pkey = NULL,
  tbl_name = NULL, export = FALSE, path = NULL, ...)

Arguments

pg_fields

a named character vector or a named list of named character vectors

schema

an optional argument to specify the desired schema for CREATE TABLE

pkey

a character string specifying the primary for the Postgres (PRIMARY KEY and CONSTRAINT)

tbl_name

a require option if nchar_df argument is a data.frame

export

a logical option export the result as an binary file

path

a file path option to specify the write location of the binary file

...

other arguments passed to glue_sql()

Details

NOTE: write_pg() does not use the SQL statement to write to PostgreSQL, but solely uses the result from set_pgfields()

Value

results in a SQL statement to CREATE TABLE. See DBI::SQL

Examples

## Not run: 
nchar_df <- get_nchar(iris)

my_pgfields <- set_pgfields(nchar_df, conn = local_con_test)

get_sql_create(my_pg_fields, pkey = "Species", tbl_name = "iris")

## End(Not run)

eugejoh/pgtools documentation built on Dec. 11, 2022, 4:29 p.m.