小编Dee*_*mar的帖子

postgres select for update查询含义

以下查询在 postgres 中意味着什么?我知道这与锁定有关,但有人可以解释一下。

select col1, col2 from table where col1=123 for update;
Run Code Online (Sandbox Code Playgroud)

实际上我有一张像这样的桌子

id  col1  col2  receipt_id  receipt_year
1   ddd   ggg   1           2018
2   ddd   eee   2           2018
Run Code Online (Sandbox Code Playgroud)

我需要每年将receipt_id重置为1。即1/2017、1/2018等。我正在使用查询

select max(receipt_id) from table where receipt_year=$current_year;
Run Code Online (Sandbox Code Playgroud)

然后如果找到 id,我将其添加 1,否则我将其设置为 1。

这是正确的方法吗?

id  col1  col2  receipt_id  receipt_year
1   ddd   ggg   1           2018
2   ddd   eee   2           2018
Run Code Online (Sandbox Code Playgroud)

2019 年:

id  col1  col2  receipt_id  receipt_year
1   ddd   ggg   1           2018
2   ddd   eee   2           2018
3   lol   lpl   1           2019 
Run Code Online (Sandbox Code Playgroud)

目前我正在这样做:

$current_year = …
Run Code Online (Sandbox Code Playgroud)

php postgresql

5
推荐指数
1
解决办法
7042
查看次数

标签 统计

php ×1

postgresql ×1