PostgreSQL选择值并立即递增 [英] PostgreSQL select value and increment at once
问题描述
我正在寻找以下问题的可能解决方案.我将数据存储在表中以跟踪客户在数据库中想要的特殊增量号.这是他们内部使用的特殊号码.
I'm looking for a possible solution to the following. I have data stored in a table to keep track of a special increment number the customer wants in the DB. This is a special number they use internally.
我想要做的是在我选择它时自动增加表格中的这个数字.所以我不存在另一个交易的问题,来自使用系统的其他人,使用相同的 ID 号.
What I would like to do is automatically increment this number in the table when I select it. So I don't have the problem of another transaction, from someone else using the system, using the same ID number.
所以我想选择当前数字并一次将它加一,这样我就没有重复了.如果可能的话,我会怎么做?
So I want to select the current number and increment it by one at once so I don't have duplicates. How would I go about doing this if it is even possible?
推荐答案
UPDATE the_table
SET the_column = the_column + 1
WHERE qualifier = X
RETURNING the_column;
这篇关于PostgreSQL选择值并立即递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!