Ruby on Rails Wednesday, June 26, 2013

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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
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.
 
 

No comments:

Post a Comment