Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2004
    Posts
    9

    Unanswered: conditioned table creation

    hi guys,

    I need to create a postgresql table with 2 columns
    name (text) and age (int) which contains two
    major conditions : the user cannot enter a name
    which begins with 'a' and a age lower than 10

  2. #2
    Join Date
    Mar 2006
    Posts
    4
    ALTER TABLE <table name>
    ADD CONSTRAINT <constraint name> CHECK (upper(substr(name::text, 1, 1)) <> 'A'::text AND age >= 10);

  3. #3
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Andy, the general term for this in database speak is a check constraint. You are constraining the potential field values by checking them against limits.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •