是否存在反向“AUTO_INCRMENT”的现有实现?在 PostgreSQL 或 MySQL 中?
无需手动执行此操作(如果不存在其他选项,我愿意实现),PostgreSQL 或 MySQL 是否有办法拥有一个自动计数器/字段来递减 增量?
由于当前应用程序中的各种原因,最好通过查看最近添加的记录(而不是减去)来知道还可以将多少条目(从数据类型的角度来看)添加到表中数据类型最大值中的最新 ID。
那么,这两个系统是否有“AUTO_DECRMENT
”或类似的功能?
Without having to do it manually (which I'm open to implementing if no other options exist), is there a way in either PostgreSQL or MySQL to have an automatic counter/field that decrements instead of increments?
For a variety of reasons in a current application, it would be nice to know how many more entries (from a datatype point of view) can still be added to a table just by looking at the most-recently-added record, rather than subtracting the most recent ID from the max for the datatype.
So, is there an "AUTO_DECREMENT
" or similar for either system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须在 PostgreSQL 中进行一些手动配置,但您可以配置这样的序列:
我想这相当于使用
serial
列创建表,然后更改自动生成的序列。现在,如果我插入一些行,我会得到 example_id 从 5 开始倒数的结果。如果我尝试插入超过 5 行,我会得到
nextval:达到序列“example_seq”的最小值 (1)
You have to do a bit of manual configuration in PostgreSQL but you can configure a sequence like that:
I suppose it would be equivalent to create the table with a
serial
column and then alter the auto-generated sequence.Now if I insert some rows I get example_id counting down from 5. If I try to insert more than 5 rows, I get
nextval: reached minimum value of sequence "example_seq" (1)