修改为指定值
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$$;
根据表的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$$;
补充:postgresql 13 数据库 sequence 的 maxvalue 最大值是多少"htmlcode">
那就需要查看下 bigint 的值 以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
# 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.
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]