# Source code for the PostgreSQLAdapter extensions. module ActiveRecord #:nodoc: module ConnectionAdapters #:nodoc: # Adds new functionality to ActiveRecord PostgreSQLAdapter. class PostgreSQLAdapter < AbstractAdapter protected # Call +bulk_load+, as that method wraps this method. # # Bulk load the data in the specified file. # # Options: # * :ignore -- Ignore the specified number of lines from the source file. In the case of PostgreSQL # only the first line will be ignored from the source file regardless of the number of lines specified. # * :columns -- Array of column names defining the source file column order # * :fields -- Hash of options for fields: # * :delimited_by -- The field delimiter # * :enclosed_by -- The field enclosure def do_bulk_load(file, table_name, options={}) q = "COPY #{table_name} " q << "(#{options[:columns].join(',')}) " if options[:columns] q << "FROM '#{File.expand_path(file)}' " if options[:fields] q << "WITH " q << "DELIMITER '#{options[:fields][:delimited_by]}' " if options[:fields][:delimited_by] if options[:fields][:enclosed_by] q << "CSV " q << "HEADER " if options[:ignore] > 0 q << "QUOTE '#{options[:fields][:enclosed_by]}' " if options[:fields][:enclosed_by] end end execute(q) end end end end