Ruby on Rails Monday, January 31, 2011

I need to generate a unique serial number in numerical order, but only unique for each user.

For example, each user can create a new credit card and each new credit card must start at a predetermined number and increment by 1 for each new credit card for that user. Thus, credit card numbers are unique for a user but not unique for the CreditCard table. And yes, it is absolutely critical that credit card numbers are always unique for each user.

I'm using PostgreSQL.

Looking through the docs it doesn't appear that I can use either pessimistic locking or optimistic locking. Maybe I'm wrong?

Is my only option to lock the table, find the highest credit card number, add 1, update the new credit card number, save, and release the table lock?


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment