createTABLE {pgTools}R Documentation

Generate a PostgreSQL CREATE TABLE statement, optionally execute the statement if con is not NULL.

Description

Generate a PostgreSQL CREATE TABLE statement, optionally execute the statement if con is not NULL.

Usage

createTABLE(
  name,
  columns,
  select = NULL,
  constraints = NULL,
  temporary = FALSE,
  if_not_exists = FALSE,
  unlogged = FALSE,
  con = NULL
)

Arguments

name

A string, the "table_name" parameter for PostgreSQL CREATE TABLE.

columns

A named list, names are the SQL column names, values are strings with the SQL column data types, constraints, etc.

select

A string, the select statement to use to create the table.

constraints

A named list, names are the SQL constraint names, values are strings with the SQL constraint.

temporary

TRUE/FALSE, if TRUE, adds "TEMPORARY" to PostgreSQL CREATE TABLE statement.

if_not_exists

TRUE/FALSE, if TRUE, adds "IF NOT EXISTS" to PostgreSQL CREATE TABLE statement.

unlogged

TRUE/FALSE, if TRUE, adds "UNLOGGED" to PostgreSQL CREATE TABLE statement.

con

A database connection that can be passed to DBI::dbSendQuery/DBI::dbGetQuery.

Value

A string, PostgreSQL CREATE TABLE statement; or the results retrieved by DBI::dbSendQuery after executing the statement.

Examples

createTABLE(
name = "sample",
columns = list(col1 = "SERIAL NOT NULL", col2 = "INTEGER", col3 = "TEXT"),
constraints = list(sample_constraint = "UNIQUE(col3)")
)

[Package pgTools version 1.0.2 Index]