If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Informix > Generate unique integer inside stored procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-06-06, 08:53
exterminator exterminator is offline
Registered User
 
Join Date: Jan 2006
Posts: 38
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.
Reply With Quote
  #2 (permalink)  
Old 03-06-06, 15:25
artemka artemka is offline
Registered User
 
Join Date: May 2004
Location: New York
Posts: 248
create a table with serial column and just keep getting a number from it
Reply With Quote
  #3 (permalink)  
Old 03-07-06, 01:25
exterminator exterminator is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 03-07-06, 10:14
artemka artemka is offline
Registered User
 
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?
Reply With Quote
  #5 (permalink)  
Old 03-08-06, 01:43
exterminator exterminator is offline
Registered User
 
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?
Reply With Quote
  #6 (permalink)  
Old 03-10-06, 10:31
artemka artemka is offline
Registered User
 
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
Reply With Quote
  #7 (permalink)  
Old 03-14-06, 07:26
exterminator exterminator is offline
Registered User
 
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...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On