write_pgtable: Write 'data.frames' to Postgres

View source: R/write_pgtable.R

write_pgtableR Documentation

Write data.frames to Postgres

Description

This function takes a data.frame or a list of data.frames and writes them to a specified schema using your database connection conn. Field types should be specified, it not the default values from dbDataType() will be used.

Usage

write_pgtable(conn, input, field.types = NULL, schema = "public",
  tbl_name = NULL, tbl.comments = NULL, field.comments = NULL,
  clean_vars = FALSE, verbose = TRUE, ...)

Arguments

conn

a object inheriting from DBIDriver or DBIConnection.

input

a data.frame or list of data frames.

field.types

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

schema

an optional argument to specify the desired database schema location, default is public

tbl_name

a required option if nchar_df argument is a single data.frame

tbl.comments

an optional argument to include a comment for the table being written, if a list it must be named

field.comments

an optional argument to include comments for each field type within the table being written , if a list it must be named

clean_vars

an optional logical argument that automatically cleans field names to be compatible with Postgres (removes upper-case and periods)

verbose

a logical argument whether to display messages on database writing steps

...

other arguments passed to dbWriteTable().

The clean_vars argument does not clean table names for list objects. The names of the dataframes inside the input list must be changed manually.

Details

This function is essentially a wrapper for dbWriteTable(). See details in RPostgres documentation under postgres-tables.

If input is a list of data frames, dimensions of field.types, tbl.comments, and field.comments must match input.

Value

write_pgtable() returns TRUE invisibly.

Examples

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

my_fields <- set_pgfields(nchar_df,
default = FALSE,
conn = DBI::dbConnect(RSQL::SQLite(), ":memory:"))

write_pgtable(input = iris,
field.types = my_fields,
conn = DBI::dbConnect(RSQL::SQLite(), ":memory:"),
tbl_name = "iris")

## End(Not run)


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