From 15b1c485d2c256b8e964e6cb55ca3e38e80fffbb Mon Sep 17 00:00:00 2001 From: Fortern Date: Thu, 30 Oct 2025 08:43:37 +0800 Subject: [PATCH] PostgreSQL common --- PostgreSQL/common.sql | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/PostgreSQL/common.sql b/PostgreSQL/common.sql index a7956ac..2b04ccd 100644 --- a/PostgreSQL/common.sql +++ b/PostgreSQL/common.sql @@ -21,3 +21,19 @@ ALTER DATABASE fortern REFRESH COLLATION VERSION; REINDEX DATABASE kt_shop; ALTER DATABASE kt_shop REFRESH COLLATION VERSION; + +-- 重置某表的某列的自增序列 [表名]_[列名]_seq +ALTER SEQUENCE person_id_seq RESTART WITH 4284858; + +-- ctid 会返回一个元组,元组中第一个数字是 page number, 第二个是 slot number。 +select r.ctid, r.* from study.r; +-- 得到 +-- "(0,1)",1,101 +-- "(0,2)",2,102 +-- "(0,3)",3,103 + +-- 删除一条 +delete from study.r where id = 2; +-- 在重新查询,得到 +-- "(0,1)",1,101 +-- "(0,3)",3,103