I have a DB table for my Rails 3.2.8 app as a PostgreSQL database. In this DB I have a column of type boolean. The column has values filled in. I want to change the values from boolean to all strings.
I found out that I can run a migration to change the type of the column. However, I don’t want to do this as yet as I’m not sure what happens to the values when I run such a migration. So would the boolean value false get changed to “False” and a boolean true to “True”?
If not then what is the best way of accomplishing this task?
You’ll probably get
'true'and'false':I’m not sure if that’s guaranteed and I can’t find an authoritative reference for what a boolean to text cast does so you might want to check what these have to say in your version of PostgreSQL:
If you want to guarantee
'True'and'False'then you can use USING to manually specify the conversion:So you could say this to force the issue:
If you let Rails do the conversion with a standard migration then you’ll get the default boolean-to-text casts, if you do the type change by hand with an SQL ALTER TABLE then you can control what happens. You can do either one inside a migration:
versus
As an aside, I’d have to question the logic of abandoning boolean columns for text columns, seems a bit backwards to me.