Skip to content

Instantly share code, notes, and snippets.

@linjunpop
Last active December 17, 2015 04:48
Show Gist options
  • Select an option

  • Save linjunpop/5552973 to your computer and use it in GitHub Desktop.

Select an option

Save linjunpop/5552973 to your computer and use it in GitHub Desktop.
https://github.com/dockyard/postgres_ext Integer Array save with String value.
rails (3.2.13)
pg (0.14.1)
pg_array_parser (0.0.8)
postgres_ext (0.3.1)
activerecord (~> 3.2.0)
pg_array_parser (~> 0.0.8)
class AddSeenByToDocuments < ActiveRecord::Migration
def change
add_column :documents, :seen_by, :integer, array: true, default: []
end
end
[19] pry(main)> d.seen_by = [4, "f"]
=> [4, "f"]
[20] pry(main)> d.save
...
(1.2ms) UPDATE "documents" SET "seen_by" = '{4,0}' ...
...
=> true
[21] pry(main)> d.reload.seen_by
Document Load (0.6ms) SELECT "documents".* FROM "documents" WHERE "documents"."id" = $1 LIMIT 1 [["id", 108]]
=> [4, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment