I need to add 1 to column value for a record in postgres table based on some filter. Suppose I have two fields id
and count
and I want to increment count value by 1.
So far I have
MyTable.filter(_.id === someId).map(_.count).update(??)
Not sure how if it is possible to use update
to do so. Any suggestion?
First, create a sequence object and set the next value generated by the sequence as the default value for the column. Second, add a NOT NULL constraint to the id column because a sequence always generates an integer, which is a non-null value.
PostgreSQL has the data types smallserial, serial and bigserial; these are not true types, but merely a notational convenience for creating unique identifier columns. These are similar to AUTO_INCREMENT property supported by some other databases.
Currently, this is not supported in Slick - https://github.com/slick/slick/issues/497. You could:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With