PostgreSQL 等同于 SQL 服务器的 IDENTITY(1, 2)

PostgreSQL equivalent of SQL Server's IDENTITY(1, 2)

有这个样本table:

create table testingCase (
id integer not null GENERATED ALWAYS AS IDENTITY,
constraint pk_testingCase primary key (id),
description varchar(60)
);

我希望 id AUTO INCREMENTED 加 2(例如),在 SQL Server 中是 IDENTITY (1, 2).

如何利用 PostgreSQL 实现这一点?

使用 CREATE SEQUENCE.

中的顺序选项
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)