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 6010035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:03:31+00:00 2026-05-23T02:03:31+00:00

Edit: Is it possible to create a unique auto increment field that will be

  • 0

Edit:

Is it possible to create a unique auto increment field that will be incremented on creates and updates in SQL using Rails (similar to an id field but incremented and re-assigned after an update)? For example:

Create Record A (Value: 1)
Create Record B (Value: 2)
Update Record A (Value: 3)
Update Record B (Value: 4)

I’m trying to setup pull synchronization and need a way to grab all records that have been created or updated since a previous synchronization.

I initially used the ‘created_at’ and ‘updated_at’ fields, but found them to be difficult to work with and somewhat inaccurate for partial synchronizations.

Edit:

I’m using Postgresql and Sqlite as my databases, so hopefully a solution exists that will work for both systems.

Edit:

To clarify, I want to pass a single integer to my server from the client (the largest ‘sync’ integer) and get back all the records created or updated after that record was created or updated.

  • 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-05-23T02:03:32+00:00Added an answer on May 23, 2026 at 2:03 am

    Ended up adding a sequence integer field to my model and setup the following migration:

    class CreateSequence < ActiveRecord::Migration
      def self.up
        begin
          execute "CREATE SEQUENCE sequence"
        rescue
        end
      end
    
      def self.down
        begin
          execute "DROP SEQUENCE sequence"
        rescue
        end
      end
    end
    

    Then, in my model I added:

    before_save do
      self.sequence = self.class.sequence
    end
    
    def self.sequence
      s ||= self.connection.select_value("SELECT nextval('sequence') ") rescue nil
      s ||= self.connection.select_value("SELECT strftime('%s','now')") rescue nil
      return 
    end
    

    Note: For Sqlite sequences are not supported so instead a selection of an ‘epoch’ form the database is required. However, this has the negative side effect of causing the sequence to be non-unique for rapid creation. However, in my case this was not an issue.

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

Sidebar

Related Questions

Is that possible to create an ordered list of arrays in Notepad++ using the
Is it possible to edit and update a GridView cell without using <asp:TemplateField> and/or
Is it possible for php(or javascript in the worst case) to create a unique
is it possible to create this image in PHP using GD ? i know
I'm looking for a fast PRNG so that I can quickly create (semi)unique IDs
Is it possible to apply / create a YUI Button by using an element's
I'm looking to create a reusable function that will generate a random key with
I am curious it is possible to create a window without using WndProc. So
Is possible create (register) a new class in runtime using delphi. I have a
Is it possible to create an MDI application using FireMonkey in a traditional sense

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.