Module: ActiveRecordPgStuff::Connection::TemporaryTable
- Defined in:
- lib/activerecord_pg_stuff/connection/temporary_table.rb
Instance Method Summary collapse
Instance Method Details
#with_temporary_table(name, sql, &block) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/activerecord_pg_stuff/connection/temporary_table.rb', line 6 def with_temporary_table(name, sql, &block) transaction do begin sql = sql.gsub(/\n/, ' ').gsub(/ +/, ' ').strip sql = "CREATE TEMPORARY TABLE #{name} ON COMMIT DROP AS #{sql}" execute sql yield name ensure execute("DROP TABLE IF EXISTS #{name}") rescue nil end end end |