set_pgfields: Set or Assign Postgres Field Types

View source: R/set_pgfields.R

set_pgfieldsR Documentation

Set or Assign Postgres Field Types

Description

This function applies a Postgres field type based on either 1. The default output from DBI::dbDataType() or 2. A preset condition that maps R classes to a specific Postgres field types.

Usage

set_pgfields(input, nchar_df, default = FALSE, conn = NULL)

Arguments

input

a data.frame or list of data frames

nchar_df

the output from get_nchar(). If nchar_df is NULL, then set_pgfields() will call get_nchar() to calculate appropriate element lengths.

default

a logical option, default = TRUE uses DBI::dbDataType()

conn

a object inheriting from DBIDriver or DBIConnection

Details

Factor to character varying (n) integer to smallint numeric to real character to character varying (n)

It is suggested to run get_nchar() prior to using set_pgfields() as get_nchar() is a computationally expensive task.

Value

returns a named character vector or list of named character vectors that will be used to specify Postgres table field types when writing to the database.

Examples

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

set_pgfields(nchar_df, conn = local_con_test)

## End(Not run)

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