0

I'm populating my PostgreSQL using a Ruby on Rails rake task. I'd like to use a PostgreSQL array function (specifically, text_to_array) on every cell in my data table. How do I do so? Can I do so within the rake task?

See related: Rails - import CSV entry as array in PostgreSQL

Community
  • 1
  • 1
user1274740
  • 83
  • 1
  • 9
  • Didn't you just ask this earlier? What's different? http://stackoverflow.com/q/22651755/398670 – Craig Ringer Mar 27 '14 at 01:56
  • That other question involved using Ruby in the rake task. It didn't ask about using PostgreSQL code in a rake task. – user1274740 Mar 27 '14 at 02:40
  • OK, that makes sense. What do you intend to *do* with the output of `text_to_array`? Are you trying to change a column data type? – Craig Ringer Mar 27 '14 at 02:49
  • I'd like to put the output (a text array) into my PostgreSQL database so that I can query elements of that array. For example, if I start with "Subway; McDonald's", I'd like to change the entry to ["Subway", "McDonald's"] so that I can look up all instances of "Subway" in the corresponding column. Does that make sense? – user1274740 Mar 27 '14 at 02:58
  • OK, so you *do* want to change the column data type - presumably from `text` to `text[]`. For that, you should use a Rails migration, using the `change_column` migration and a `USING` expression that uses `text_to_array`. Hopefully that gives you some idea where to start looking; I don't have time to write a full answer right now. – Craig Ringer Mar 27 '14 at 03:04
  • Thanks! Appreciate it - I'll look around. – user1274740 Mar 27 '14 at 03:07

0 Answers0