2

I have a table which uses O.AutoInc as ID generator, which is a primary key.

Sample Code:

case class User(id:Long)
class UsersTable(tag: Tag) extends Table[User](tag,"USERS"){
   def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
   def * = (id) <> (User.tupled, User.unapply)
}

This creates a table with SERIAL field and a sequence with start value 1. Is there a way to change this start value?

Another option is to create sequence like:

Sequence[Long]("USERS_ID_seq") start 200000 inc 1

and use it something like:

def id = column[Long]("ID", O.PrimaryKey, O.DBType("nextval('USERS_ID_seq')"))

I am not sure whether it will work as I cant find a way to make play use this sequence.

So is there a way to tell play evolution to use this sequence?

Johny T Koshy
  • 3,857
  • 2
  • 23
  • 40
  • You can use O.default, like this: `def id = column[Long]("id", O.PrimaryKey, O.AutoInc, O.NotNull,O.Default(100000))`. For more info: [link](http://stackoverflow.com/questions/21756514/start-generating-auto-increment-column-value-from-default-in-slick) – Bla... Jul 06 '14 at 09:15
  • @user3003216, it wont work. That answer is wrong. O.AutoInc creates a SERIAL field and it has a default for the SEQUENCE it automatically generated. Now if I add O.Default, it will create two defaults. – Johny T Koshy Jul 06 '14 at 11:45
  • Why would you use 2 Sequences at a time ? Choose one, either use your current code or add O.Default. – Bla... Jul 06 '14 at 13:11
  • The specified part is in the last of this link. http://www.postgresql.org/docs/9.1/static/datatype-numeric.html – Johny T Koshy Jul 06 '14 at 13:20

0 Answers0