Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    11

    Unanswered: How to limit serial8 incremental.

    I would like to define a column that auto-increment but it should be bigger than serial type but it should be less than the max serial8. So I want to define the column type as serial8. But i want to limit the incremental on 12 integers. I want to throw an error if the incremental reaches 12 integers. is there any way to do it in the ddl?

  2. #2
    Join Date
    Sep 2011
    Location
    Pont l'Abbé, Brittany, France
    Posts
    381
    Provided Answers: 1
    Hi,

    I would use a check constraint at the column level, something like

    create table tablename (
    col1 char(20),
    col2 serial8 CHECK (col2 BETWEEN 0 AND 999999999999),
    etc...

    If the value is above the indicated value, the application will received a check constraint violation error ( probably -6nn error or so, just test and check).
    You can handle it as a normal error in your application.

    Hope this helps
    Eric

  3. #3
    Join Date
    Feb 2004
    Posts
    11
    Thanks a lot. It works perfect.

  4. #4
    Join Date
    Sep 2011
    Location
    Pont l'Abbé, Brittany, France
    Posts
    381
    Provided Answers: 1
    You just chose the best way to implement your scenario

    Congrats!

    Eric

Posting Permissions

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