Create Unique IDs in a given table
We have a concrete Pega table which we would like to generate unique values (for insert). Currently we have imported the records from an excel spreadsheet; however, if we are to allow the customer to add records themselves, we will need to generated new unique keys/ids.
For example, we have an organization table; which has ORG_ID as the primary key. If we want the user to add a new Organization, how do we generate the new key? Ideally, we would like to make a call to get the next sequence (specific to the Organization table). If the last record in the Organization table has an ORG_ID of 1100, then we want the next record generated to be 1101 (and so on).
I realize that we can query the entire Organziation table for the max(ORG_ID); however, that seems very inefficient. Is there an easier way to generate the new unique sequence ID?
In PostgreSQL, you can use the SERIAL data type to automatically generate unique integer numbers for a column, in this case, ORG_ID.
Check this link for an example: http://www.sqlines.com/postgresql/datatypes/serial
Keep up to date on this post and subscribe to comments