## Not run:
# library(sp)
# data(meuse)
# coords <- SpatialPoints(meuse[, c("x", "y")])
# spdf <- SpatialPointsDataFrame(coords, meuse)
#
# ## Format data for insert
# pgi.new <- pgInsertizeGeom(spdf, geom = "point_geom", create.table = c("schema",
# "table"), new.id = "pt_gid")
# print(pgi.new)
#
# ## Insert data in database table (note that an error will be given if
# ## all insert columns do not have exactly matching database table
# ## columns)
# pgInsert(conn = conn, data.obj = pgi.new)
#
# ## Inserting into existing table
# pgi.existing <- pgInsertizeGeom(spdf, geom = "point_geom", force.match = c("schema",
# "table"), conn = conn)
# ## A warning message is given, since the "dist.m" column is not found
# ## in the database table (it was changed to "dist_m" in pgi.new to
# ## make name DB-compliant). All other columns are prepared for insert.
# print(pgi.existing)
#
# pgInsert(conn = conn, data.obj = pgi.existing)
# ## End(Not run)
## Not run:
# ## Format regular (non-spatial) data frame for insert using
# ## pgInsertize connect to database
# data <- data.frame(a = c(1, 2, 3), b = c(4, NA, 6), c = c(7,
# "text", 9))
#
# ## Format non-spatial data frame for insert
# values <- pgInsertize(data.obj = data)
#
# ## Insert data in database table (note that an error will be given if
# ## all insert columns do not match exactly to database table columns)
# pgInsert(conn, data.obj = values, name = c("schema", "table"))
#
# ## Run with forced matching of database table column names
# values <- pgInsertize(data.obj = data, force.match = c("schema",
# "table"), conn = conn)
#
# pgInsert(conn, data.obj = values)
# ## End(Not run)
Run the code above in your browser using DataLab