Class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
In: lib/adapter_extensions/connection_adapters/postgresql_adapter.rb
Parent: AbstractAdapter

Adds new functionality to ActiveRecord PostgreSQLAdapter.

Methods

Public Instance methods

Inserts an INTO table_name clause to the sql_query.

[Source]

    # File lib/adapter_extensions/connection_adapters/postgresql_adapter.rb, line 11
11:       def add_select_into_table(new_table_name, sql_query)
12:         sql_query.sub(/FROM/i, "INTO #{new_table_name} FROM")
13:       end

Copy the specified table.

[Source]

    # File lib/adapter_extensions/connection_adapters/postgresql_adapter.rb, line 16
16:       def copy_table(old_table_name, new_table_name)
17:         execute add_select_into_table(new_table_name, "SELECT * FROM #{old_table_name}")
18:       end

[Source]

   # File lib/adapter_extensions/connection_adapters/postgresql_adapter.rb, line 6
6:       def support_select_into_table?
7:         true
8:       end

Protected Instance methods

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
  • :null_string — The string that should be interpreted as NULL (in addition to \N)
  • :enclosed_by — The field enclosure

[Source]

    # File lib/adapter_extensions/connection_adapters/postgresql_adapter.rb, line 33
33:       def do_bulk_load(file, table_name, options={})
34:         q = "COPY #{table_name} "
35:         q << "(#{options[:columns].join(',')}) " if options[:columns]
36:         q << "FROM '#{File.expand_path(file)}' "
37:         if options[:fields]
38:           q << "WITH "
39:           q << "DELIMITER '#{options[:fields][:delimited_by]}' " if options[:fields][:delimited_by]
40:           q << "NULL '#{options[:fields][:null_string]}'" if options[:fields][:null_string]
41:           if options[:fields][:enclosed_by] || options[:ignore] && options[:ignore] > 0
42:             q << "CSV "
43:             q << "HEADER " if options[:ignore] && options[:ignore] > 0
44:             q << "QUOTE '#{options[:fields][:enclosed_by]}' " if options[:fields][:enclosed_by]
45:           end
46:         end
47:         
48:         execute(q)
49:       end

[Validate]