I am accessing my PostgreSQL database (9.3) via R using the RPostgreSQL package.
I have a few very long and big sql queries (several MB big. generated from raster2pgsql).
How can I send / execute sql query files as statement within R?
The normal way
\i query.sql
does not seem to work via dbSendQuery.
I tried to read in the whole sql file as character vector via readLines, however this also fails, because dbSendQuery only supports a single command apparently?
dbSendQueryordbGetQueryis just for the "SQL" part, not the psql commands such as\i.In your case the simplest is indeed to use
readLinesbut then wrapdbGetQueryin asapplycall.Since I use this very often, I have a shortcut for this in my
.Rprofilefile:Of course, you can also go the
systemway: