Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9062457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:44:34+00:00 2026-06-16T15:44:34+00:00

I have a DB table for my Rails 3.2.8 app as a PostgreSQL database.

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:44:35+00:00Added an answer on June 16, 2026 at 3:44 pm

    You’ll probably get 'true' and 'false':

    psql> create table t (c boolean not null);
    psql> insert into t (c) values (TRUE), (FALSE);
    psql> alter table t alter column c type text;
    psql> select * from t;
       c   
    -------
     true
     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:

    psql> select TRUE::text;
    psql> select FALSE::text;
    

    If you want to guarantee 'True' and 'False' then you can use USING to manually specify the conversion:

    The optional USING clause specifies how to compute the new column value from the old; if omitted, the default conversion is the same as an assignment cast from old data type to new.

    So you could say this to force the issue:

    alter table t
    alter column c type text
    using case c when TRUE then 'True' when FALSE then 'False' else NULL end
    

    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:

    def up
        change_column :t, :c, :text
    end
    

    versus

    def up
        connection.execute(%q{
            alter table ...
        })
    end
    

    As an aside, I’d have to question the logic of abandoning boolean columns for text columns, seems a bit backwards to me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Ruby on Rails app with a PostgreSQL database which has this
I have Rails app with a PostgreSQL DB Sales Table that looks like this:
I have a Ruby/Rails app. I have an artists table in my postgresql database
Hi I have a rails app which has a table called listings. This table
I have a rails app with a PostgreSQL database with hourly price data for
I have a Rails app using a Postgres database with a table called geolite_blocks.
So in a rails app I have a table in my database, hard drives,
I have table and this table contain result column with some entries. I just
Hi I have a table in my rails app that doesnt have any id
In my Rails app, I set up my users table to have a string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.