Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8801031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:44:14+00:00 2026-06-14T00:44:14+00:00

In a Rails app I need a source of unique, sequential (no gaps) integers

  • 0

In a Rails app I need a source of unique, sequential (no gaps) integers to use as serial numbers. It must be persistent and allow concurrent access.

Database auto-increment isn’t adequate because most don’t guarentee the “no gaps” property.

In straight SQL I would just create a one-line table and say (in PostgreSQL) something like:

update sequence set value = value + 1 returning value

This is apparently standard practice in the SQL world. References exist.

In ActiveRecord I easily created a model the model and found .increment! and .increment_counter in the documentation. But I can’t figure out how to atomically retrieve the incremented value. Locks and transactions don’t seem to help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:44:16+00:00Added an answer on June 14, 2026 at 12:44 am

    If you want to use redis (and maybe you already are because of Resque or Sidekiq), you can do an INCR on a key, this is atomic and returns the new value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a small rails app and I need a way to generate
I need some references for creating a Rails app where each client/company has his
I have a Rails app that does everything I need it to do via
I have a Rails app running Mongoid on Heroku and I need to set
So I need to access this service from my rails app. I'm using soap4r
I need to produce somewhat complicated PDFs from a Rails app - tables with
I need to start a copy of a Rails app from within Java. I
I need to implement fine-grained access control in a Ruby on Rails app. The
We have the rails app, content served from the database. Now we need to
I have an XML view in a rails app, and need to insert in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.