0

How can I create a field (non-primary id) in a rails table that auto_increments like an id but that starts from the number 10,000? My app is using sqlite3 and rails 4.

Thank you

The suggested solution does not address my question. I was looking for a raw SQL answer.

davefogo
  • 93
  • 1
  • 9
  • 1
    possible duplicate of [Set start value for AUTOINCREMENT in SQLite](http://stackoverflow.com/questions/692856/set-start-value-for-autoincrement-in-sqlite) – Marc B Apr 01 '15 at 21:21
  • This answer does not answer my question. I was looking for a solution using raw sql. – davefogo Apr 01 '15 at 22:51
  • Why do you want to do that? Please describe what you try to achieve. – spickermann Apr 02 '15 at 00:23

1 Answers1

0

If you had two auto increment columns on one table both value would always be in sync (with an offset given by the start value). Therefore it doesn't make much sense to have two independent auto increment columns on one table. It would just be a waste of diskspace.

That said: Some database engines support combined auto increment columns (auto increment columns that depend on other columns), but afaik no engine support two independent columns.

A simple work around would be something like this:

def secondary_id
  id + 10_000
end
spickermann
  • 100,941
  • 9
  • 101
  • 131