All that PgAdmin-III's "import tool" does is run the COPY
command. If you enable log_statement = 'all'
in postgresql.conf
and examine the server logs you'll see it.
You can instead use the psql
\copy
command from a script to achieve the same thing.
This won't work with SQL run via other clients, though, as COPY
is a special command that switches into a special line-by-line input mode that things like the Ruby Pg gem generally don't support directly. The Pg gem does support COPY
via the copy_data
method, so you can use it from Ruby code, but then you have to open the CSVs yourself in Ruby, etc. It's pretty simple, and that's how I'd do it if I wanted to use a Rake task.
Another option is to use server-side COPY
, where you pass PostgreSQL the path of the file to load directly. This is fastest, but requires the PostgreSQL server to have permission to read the file, and the file to be on the same computer as the server. So it's not very flexible.
I recommend using the Pg gem with copy_data
in your Rake script.