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 8653305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:30:44+00:00 2026-06-12T14:30:44+00:00

I’ve started working on a project where there is a fairly large table (about

  • 0

I’ve started working on a project where there is a fairly large table (about 82,000,000 rows) that I think is very bloated. One of the fields is defined as:

consistency character varying NOT NULL DEFAULT 'Y'::character varying

It’s used as a boolean, the values should always either be (‘Y’|’N’).

Note: there is no check constraint, etc.

I’m trying to come up with reasons to justify changing this field. Here is what I have:

  • It’s being used as a boolean, so make it that. Explicit is better than implicit.
  • It will protect against coding errors because right now there anything that can be converted to text will go blindly in there.

Here are my question(s).

  • What about size/storage? The db is UTF-8. So, I think there really isn’t much of a savings in that regard. It should be 1 byte for a boolean, but also 1 byte for a 'Y' in UTF-8 (at least that’s what I get when I check the length in Python). Is there any other storage overhead here that would be saved?
  • Query performance? Will Postgres get any performance gains for a where cause of “=TRUE” vs. “='Y'“?
  • 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-12T14:30:45+00:00Added an answer on June 12, 2026 at 2:30 pm

    PostgreSQL (unlike Oracle) has a fully-fledged boolean type. Generally, a "yes/no flag" should be boolean. That’s the appropriate type!

    What about size/storage?

    A boolean column occupies 1 byte on disk.
    (The manual) about text or character varying:

    the storage requirement for a short string (up to 126 bytes) is 1 byte
    plus the actual string

    That’s at least 2 bytes for a single character.

    Actual storage is more complicated than that. There is some fixed overhead per table, page and row, there is special NULL storage and some types require data alignment. See:

    • How many records can I store in 5 MB of PostgreSQL on Heroku?

    Encoding UTF8 doesn’t make any difference here. Basic ASCII-characters are bit-compatible with other encodings like LATIN-1.

    In your case, according to your description, you should keep the NOT NULL constraint you already have – independent of the data type.

    Query performance?

    Will be slightly better in any case with boolean. Besides being smaller, the logic for boolean is simpler and varchar or text are also generally burdened with COLLATION rules. But don’t expect much for something that simple.

    Instead of:

    WHERE consistency = 'Y'
    

    You could write:

    WHERE consistency = true
    

    But rather simplify to just:

    WHERE consistency
    

    No further evaluation needed.

    Change type

    Transforming your table is simple:

    ALTER TABLE tbl ALTER consistency TYPE boolean
    USING CASE consistency WHEN 'Y' THEN true ELSE false END;
    

    This CASE expression folds everything that is not TRUE (‘Y’) to FALSE. The NOT NULL constraint just stays.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

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.