sql - PostgreSQL 等效于 SQL Server 的 IDENTITY(1, 2)
问题描述
有这个样本表:
create table testingCase (
id integer not null GENERATED ALWAYS AS IDENTITY,
constraint pk_testingCase primary key (id),
description varchar(60)
);
我希望 id自动增加 2 (例如),SQL Server
因为那是IDENTITY (1, 2)
.
如何使用 PostgreSQL 来实现这一点?
解决方案
create table testing_case (
id integer not null generated always as identity (increment by 2),
constraint pk_testing_case primary key (id),
description varchar(60)
);
insert into testing_case (description)
values ('a'), ('b'), ('c')
returning *
id | description
----+-------------
1 | a
3 | b
5 | c
(3 rows)
推荐阅读
- python - Python子进程中的Awk不起作用
- android - 更新 Android SDK
- java - 在 Java 中使用范围查找枚举
- hadoop - 支持 Tez 的抢占以及纱线 FairShare 调度程序?
- c# - Grid 中的 SyncFusion WPF ComboBox - 如何在 OnCommitCellInfo 事件上设置显示文本
- php - 如何获取每个菜单项的链接并将其链接到 WordPress 的页面上?
- java - 告诉 Hibernate 不要删除库项目的实体
- sql-server - SQL Server:为什么即使使用了搜索,也会发生扫描?
- android - 使用 Android Studio 安装的 Android 应用可以运行几个月吗?
- python - 如何使用 for 循环影响列表的显示?