只在數(shù)據(jù)庫postgre中實(shí)驗(yàn)了,親測有效。
1ROW_NUMBER () OVER (ORDER BY col_name ASC) AS ids
下面是我的實(shí)驗(yàn)截圖:
補(bǔ)充:postgresql給已有的字段創(chuàng)建添加自增,并且自增值從最大的id+1開始
/*修改表的id屬性為自增*/
CREATE SEQUENCE test_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
start with 序列開始值
increment by 遞增值
給表添加自增屬性
alter table testalter column id set default nextval('test_id_seq');
將下一次的自增值設(shè)置成最大id+1
1select setval('test_id_seq',(select max(id)+1 from asset_detect_task));
文章來源:腳本之家
來源地址:https://www.jb51.net/article/205270.htm
申請創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!