简体   繁体   English

使用Slick for postgres增加列值

[英]Increment column value using Slick for postgres

I need to add 1 to column value for a record in postgres table based on some filter. 我需要根据一些过滤器为postgres表中的记录添加1到列值。 Suppose I have two fields id and count and I want to increment count value by 1. 假设我有两个字段idcount ,我想将计数值增加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. 不确定如何使用update来执行此操作。 Any suggestion? 有什么建议吗?

Currently, this is not supported in Slick - https://github.com/slick/slick/issues/497 . 目前,Slick不支持此功能 - https://github.com/slick/slick/issues/497 You could: 你可以:

  1. Use a plain SQL query; 使用纯SQL查询; or 要么
  2. Retrieve the current "count" value in a separate query, increment, then do the update, using the transactionally modifier to force the use of one transaction. 在单独的查询中检索当前“count”值,递增,然后使用事务修饰符执行更新以强制使用一个事务。 Though, depending on the level of transaction isolation in your database, the use of a transaction might not be enough to avoid race conditions. 但是,根据数据库中事务隔离的级别,使用事务可能不足以避免竞争条件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM