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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:33:17+00:00 2026-06-05T10:33:17+00:00

I have been migrating a MySQL db to Pg (9.1), and have been emulating

  • 0

I have been migrating a MySQL db to Pg (9.1), and have been emulating MySQL ENUM data types by creating a new data type in Pg, and then using that as the column definition. My question — could I, and would it be better to, use a CHECK CONSTRAINT instead? The MySQL ENUM types are implemented to enforce specific values entries in the rows. Could that be done with a CHECK CONSTRAINT? and, if yes, would it be better (or worse)?

  • 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-05T10:33:18+00:00Added an answer on June 5, 2026 at 10:33 am

    Based on the comments and answers here, and some rudimentary research, I have the following summary to offer for comments from the Postgres-erati. Will really appreciate your input.

    There are three ways to restrict entries in a Postgres database table column. Consider a table to store “colors” where you want only ‘red’, ‘green’, or ‘blue’ to be valid entries.

    1. Enumerated data type

      CREATE TYPE valid_colors AS ENUM ('red', 'green', 'blue');
      
      CREATE TABLE t (
          color VALID_COLORS
      );
      

      Advantages are that the type can be defined once and then reused in as many tables as needed. A standard query can list all the values for an ENUM type, and can be used to make application form widgets.

      SELECT  n.nspname AS enum_schema,  
              t.typname AS enum_name,  
              e.enumlabel AS enum_value
      FROM    pg_type t JOIN 
              pg_enum e ON t.oid = e.enumtypid JOIN 
              pg_catalog.pg_namespace n ON n.oid = t.typnamespace
      WHERE   t.typname = 'valid_colors'
      
       enum_schema | enum_name     | enum_value 
      -------------+---------------+------------
       public      | valid_colors  | red
       public      | valid_colors  | green
       public      | valid_colors  | blue
      

      Disadvantages are, the ENUM type is stored in system catalogs, so a query as above is required to view its definition. These values are not apparent when viewing the table definition. And, since an ENUM type is actually a data type separate from the built in NUMERIC and TEXT data types, the regular numeric and string operators and functions don’t work on it. So, one can’t do a query like

      SELECT FROM t WHERE color LIKE 'bl%'; 
      
    2. Check constraints

      CREATE TABLE t (
          colors TEXT CHECK (colors IN ('red', 'green', 'blue'))
      );
      

      Two advantage are that, one, “what you see is what you get,” that is, the valid values for the column are recorded right in the table definition, and two, all native string or numeric operators work.

    3. Foreign keys

      CREATE TABLE valid_colors (
          id SERIAL PRIMARY KEY NOT NULL,
          color TEXT
      );
      
      INSERT INTO valid_colors (color) VALUES 
          ('red'),
          ('green'),
          ('blue');
      
      CREATE TABLE t (
          color_id INTEGER REFERENCES valid_colors (id)
      );
      

      Essentially the same as creating an ENUM type, except, the native numeric or string operators work, and one doesn’t have to query system catalogs to discover the valid values. A join is required to link the color_id to the desired text value.

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

Sidebar

Related Questions

We have a server farm that we are slowly migrating to a new version
we have been using ThreadLocal so far to carry some data so as to
I have Core Data application and I have been migrating (upgrading) the core data
I have been put in charge of migrating the data out of an MS
Have been following this fabulous tutorial . Being new to Javascript and functional programming,
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been using the examples from this site ( http://dojotoolkit.org/documentation/tutorials/1.6/datagrid/ ) to render
I have been tasked with migrating an existing mature ASP.NET 2.0 web site to
I was a MySQL user. Now I'm migrating to SQL Server. But I have
I have been using the following regular expression in ASP.NET and Javascript: [a-zA-ZöäüÖÄÜß0-9]{1}[a-zA-ZöäüÖÄÜß0-9_.\-]{2,14}[a-zA-ZöäüÖÄÜß0-9.!]{1} Now,

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.