class Purview::Loaders::PostgreSQL
Private Instance Methods
dialect_type()
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 6 def dialect_type Purview::Dialects::PostgreSQL end
id_in_sql(temporary_table_name)
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 10 def id_in_sql(temporary_table_name) 'SELECT %s FROM %s' % [ table.id_column.name, temporary_table_name, ] end
in_window_sql(window)
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 17 def in_window_sql(window) '%s BETWEEN %s AND %s' % [ table.updated_timestamp_column.name, quoted(window.min), quoted(window.max), ] end
not_in_window_sql(window)
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 25 def not_in_window_sql(window) '%s NOT BETWEEN %s AND %s' % [ table.updated_timestamp_column.name, quoted(window.min), quoted(window.max), ] end
table_delete_sql(window, temporary_table_name)
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 33 def table_delete_sql(window, temporary_table_name) 'DELETE FROM %s WHERE %s AND %s NOT IN (%s)' % [ table.name, in_window_sql(window), table.id_column.name, id_in_sql(temporary_table_name), ] end
table_insert_sql(window, temporary_table_name)
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 42 def table_insert_sql(window, temporary_table_name) 'INSERT INTO %s (%s) SELECT %s FROM %s t1 WHERE NOT EXISTS (SELECT 1 FROM %s t2 WHERE t1.%s = t2.%s)' % [ table.name, table.column_names.join(', '), table.column_names.join(', '), temporary_table_name, table.name, table.id_column.name, table.id_column.name, ] end
table_update_sql(window, temporary_table_name)
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 54 def table_update_sql(window, temporary_table_name) 'UPDATE %s t1 SET %s FROM %s t2 WHERE t1.%s = t2.%s' % [ table.name, table.column_names.map { |column_name| "#{column_name} = t2.#{column_name}" }.join(', '), temporary_table_name, table.id_column.name, table.id_column.name, ] end
temporary_table_insert_sql(temporary_table_name, rows)
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 64 def temporary_table_insert_sql(temporary_table_name, rows) 'INSERT INTO %s (%s) VALUES %s' % [ temporary_table_name, table.column_names.join(', '), rows.map { |row| "(#{row_values(row)})" }.join(', ') ] end
temporary_table_opts()
click to toggle source
Calls superclass method
Purview::Loaders::Base#temporary_table_opts
# File lib/purview/loaders/postgresql.rb, line 72 def temporary_table_opts super.merge(:create_indices => false) end
temporary_table_verify_sql(temporary_table_name, rows, window)
click to toggle source
# File lib/purview/loaders/postgresql.rb, line 76 def temporary_table_verify_sql(temporary_table_name, rows, window) 'SELECT COUNT(1) %s FROM %s WHERE %s' % [ count_column_name, temporary_table_name, not_in_window_sql(window), ] end