Skip to content

Instantly share code, notes, and snippets.

View restore.sql
UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template0';
\c template0
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
DROP DATABASE template1;
CREATE DATABASE template1 WITH TEMPLATE = 'template0';
\c template1
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template0';
raeno / gist:8beaa77e0b5a86c2a9ec
Created Oct 21, 2014
Two outer joins on same table with Arel
View gist:8beaa77e0b5a86c2a9ec
messages = Message.arel_table
messages2 = Message.arel_table.alias('messages2')
messages3 = Message.arel_table.alias('messages3')
users = User.arel_table
manager =
manager.project users[:first_name], users[:last_name], messages[:created_at]
manager.from messages
manager.join(messages2, Arel::Nodes::OuterJoin).on(messages[:created_at].eq(messages2[:created_at]))
manager.join(messages3, Arel::Nodes::OuterJoin).on(messages[:recipient_id].eq(messages3[:recipient_id]))