When I try to insert a new record in a PostgreSQL table using Squeryl's Table.insert, it fires this query:
insert into "users" ("id", "email", "fullname") values (nextval('"s_users_id"'),?,?)
This doesn't work, as I did not define a sequence and instead defined the id column to be "autoincrement":
CREATE TABLE Users (
id BIGSERIAL,
email varchar(255) NOT NULL,
fullname varchar(255),
PRIMARY KEY (id)
);
I read some old post in another forum about this issue, and I was wondering what the status is now. Are we discouraged to use autoincrement and define a sequence instead? Or is there a simple workaround to get this working?
Edit: In fact just now I see that the autoincrement itself creates a serial, but under another name: users_id_seq Is there a way to tell Squeryl to look under this name instead, or follow PostgreSQL's convention?
You can declare name of the sequence:
case class Author(id: Long, firstName: String)
val author = table[Author]
on(author)(s => declare(
s.id is(autoIncremented("your_seq_name"))
))
more information: http://squeryl.org/schema-definition.html