sql.insert {RPgSQL}R Documentation

Append data to a PostgreSQL table

Description

sql.insert is quite useful for appending data to database tables.

Usage

sql.insert(into, column.names, values, query)

Arguments

into A character string with the table name
column.names An optional list of column names
values Data values, matrix or data frame to insert from
query An SQL query

Details

The easiest way to use sql.insert is to use the into and values arguments. Enter the table name in the into argument and set values to a data frame. sql.insert will extract the column names from the data frame and update those columns. See example below.

Author(s)

Timothy H. Keitt

See Also

db.write.table

Examples

if (db.connection.open()) {
  data(airquality)
  rpgsql.test.data <- airquality[1:5,]
  db.write.table(rpgsql.test.data, no.clobber=F)
  db.read.table('rpgsql.test.data')
  rpgsql.test.data <- airquality[6:10,]
  sql.insert(into='rpgsql.test.data', values=rpgsql.test.data)
  db.read.table('rpgsql.test.data')
  db.rm('rpgsql.test.data', ask=F)
}