Skip to content

Instantly share code, notes, and snippets.

@luxxi
luxxi / update_or_create.rb
Last active August 29, 2015 14:17
update_or_create
#Using in single model
def self.update_or_create(attributes)
obj = first || new
obj.assign_attributes(attributes)
obj
end
#User.where(email: "a@b.com").update_or_create(email: "d@e.com")
@luxxi
luxxi / postgresql-data-export.md
Last active August 28, 2015 23:29
Export data from postgresql

Use COPY TO for dump the table data in csv format.

COPY table TO '/tmp/table.csv' DELIMITER ',';

Use the COPY FROM to "paste" it in another table.

COPY another_table FROM '/tmp/table.csv' DELIMITER ',';