Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2006
    Posts
    38

    Unanswered: Generate unique integer inside stored procedure

    The question is pretty much what is there in the title. How can I generate a unique integer value inside an Informix stored procedure? Thanks for taking a look. Best regards.

  2. #2
    Join Date
    May 2004
    Location
    New York
    Posts
    248
    create a table with serial column and just keep getting a number from it

  3. #3
    Join Date
    Jan 2006
    Posts
    38
    Well, yes that is what I figured out but I faced one more issue that I ignored in the first place.

    There is a table in which I need to insert data into. There is column of my concern that is an integer. There is unique constraint that I want to avoid violating. For that I need unique integral values.

    Now what you suggested and what I am doing, will generate unique numbers but that may be there in the table where I am inserting the data.

    So the question now is - How do I get a unique integer that is not there in the table's concerned column already and if it is there how to avoid the clash?

    Thanks for having a look artemka. Best regards.

  4. #4
    Join Date
    May 2004
    Location
    New York
    Posts
    248
    if you already have values in the table then why dont you just
    select max(your integer number) from the table, add 1 to it and insert the new number back in

    will that work for you?

  5. #5
    Join Date
    Jan 2006
    Posts
    38
    Artemka, I think you think exactly the same way as I do...
    I have the same thing:
    Code:
    SELECT NVL(MAX(column_name)+1,1) FROM table_name WHERE <conditions>
    Is there any danger of exceeding the limited of the integer datatype for this? What is the maximum value an integer can take? What happens when one exceeds that value?

  6. #6
    Join Date
    May 2004
    Location
    New York
    Posts
    248
    Integer number is up there in the billions or trillions i don’t exactly remember. Good luck exceeding it )))

    Cheers

  7. #7
    Join Date
    Jan 2006
    Posts
    38
    I got this information from IBM informix documentation for IBM Informix Dynamic Server v10.0:
    Code:
    2,147,483,647 ((2 to the 31st power) - 1)
    Just for the records...

Posting Permissions

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