最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pgsql批量修改sequences的start方式

 更新時間:2020年12月29日 10:03:11   作者:_rtf  
這篇文章主要介紹了pgsql批量修改sequences的start方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

修改為指定值

DO $$DECLARE r record;
BEGIN
FOR r IN SELECT sequence_name FROM information_schema."sequences"
LOOP
 EXECUTE 'ALTER SEQUENCE '|| r.sequence_name ||' restart WITH 10000';
END LOOP;
END$$;

根據(jù)表的id修改

DO $$
DECLARE 
 r record;
 start_value integer := 0;
BEGIN
FOR r IN SELECT tablename||'_id_seq' AS sequence_name, tablename FROM pg_tables WHERE schemaname = 'public'
LOOP
 EXECUTE 'SELECT max(id)+1 AS max_value FROM ' || r.tablename INTO start_value;
 IF start_value IS NULL THEN start_value:= 1;
 END IF;
 RAISE NOTICE 'start_value % %', r.tablename,start_value;
 EXECUTE 'ALTER SEQUENCE '|| r.sequence_name ||' restart WITH ' || start_value;
END LOOP;
END$$;

補(bǔ)充:postgresql 13 數(shù)據(jù)庫 sequence 的 maxvalue 最大值是多少?

os: centos 7.8.2003

db: postgresql 13.0

版本

# cat /etc/centos-release
CentOS Linux release 7.8.2003 (Core)
# su - postgres
Last login: Thu Oct 15 09:59:33 CST 2020 on pts/1

ppostgres@nodepg13-> psql -c "select version();"
             version             
---------------------------------------------------------------------------------------------------------
 PostgreSQL 13.0 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
(1 row)

create sequence

$ psql

postgres=# create sequence seq_1;
CREATE SEQUENCE
postgres=# select c.relname,c.relkind,s.* from pg_class c,pg_sequence s where c.oid=s.seqrelid;
 relname | relkind | seqrelid | seqtypid | seqstart | seqincrement |  seqmax  | seqmin | seqcache | seqcycle 
---------+---------+----------+----------+----------+--------------+---------------------+--------+----------+----------
 seq_1 | S  | 40968 |  20 |  1 |   1 | 9223372036854775807 |  1 |  1 | f
(1 row)
seqmax = 9223372036854775807

maxvalue
NO MAXVALUE
The optional clause MAXVALUE maxvalue determines the maximum value for the sequence. If this clause is not supplied or NO MAXVALUE is specified, then default values will be used. The default for an ascending sequence is the maximum value of the data type. The default for a descending sequence is -1.

那就需要查看下 bigint 的值

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評論

西林县| 安福县| 石景山区| 柳州市| 莱西市| 黄浦区| 遂溪县| 香格里拉县| 唐河县| 永泰县| 鹤壁市| 旺苍县| 报价| 凉山| 霍山县| 孝昌县| 英山县| 吐鲁番市| 疏勒县| 常山县| 日土县| 新龙县| 齐河县| 永安市| 囊谦县| 南投市| 安福县| 新安县| 新建县| 仙居县| 兴仁县| 鄂托克旗| 桂林市| 松溪县| 吴桥县| 张北县| 芜湖县| 安阳县| 拜泉县| 沧源| 蓬溪县|