h2opbun-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2013-Jun-26 18:28 UTC
json text to text array migration questions
Hi,
I have field in postgres (9.2.4) with type json. The field looks like
Column | Type | Modifiers | Storage |
Stats target | Description
---------------------+-----------------------------+-----------+----------+--------------+-------------
my_id_field | json | | extended
| |
When I do " select my_id_field::json from table1", it returns
something like
[]
[]
[]
["abc"]
[]
[]
[]
I like to change this from type json to text[] and included the following
in the migration
execute "alter table table1 add column new_id_field text[] default
''{}''::text[]"
execute "UPDATE table1 SET new_id_field = [my_id_field] where my_id_field
is not null"
I ended up with data like [["abc"]] and [[]], which was not what I
wanted
Questions:
1) how do I convert the json type to text[]?
2) in ActiveRecord, how do I select rows from table1 that are not []?
TIA
m
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/67875bb8-b5c8-4914-8c32-f71cd94724ce%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
