在 Postgres 中为每个 id 添加序列号
Add serial number for each id in Postgres
我必须在 postgres 中使用 serno、id、名称、地址创建 table,并且 serno 应该是来自其他 table 的每个 ID 的 运行 编号。我有以下查询
CREATE TABLE Ids (SerNo integer, Id varchar(100),Name varchar(250),Address varchar(500));
INSERT INTO Ids (SerNo,Id,Name,Address)
VALUES (rank() OVER(ORDER BY "Id"),
(SELECT distinct("Id") from "Table2"),'John','US');
ERROR: window functions are not allowed in VALUES
LINE 2: VALUES (rank() OVER(ORDER BY "Id"),
请指正
使用序列:
create table Ids (SerNo serial...
insert into Ids (Id,Name,Address)
select distinct Id, 'John', 'US'
from Table2;
https://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL
我必须在 postgres 中使用 serno、id、名称、地址创建 table,并且 serno 应该是来自其他 table 的每个 ID 的 运行 编号。我有以下查询
CREATE TABLE Ids (SerNo integer, Id varchar(100),Name varchar(250),Address varchar(500));
INSERT INTO Ids (SerNo,Id,Name,Address)
VALUES (rank() OVER(ORDER BY "Id"),
(SELECT distinct("Id") from "Table2"),'John','US');
ERROR: window functions are not allowed in VALUES
LINE 2: VALUES (rank() OVER(ORDER BY "Id"),
请指正
使用序列:
create table Ids (SerNo serial...
insert into Ids (Id,Name,Address)
select distinct Id, 'John', 'US'
from Table2;
https://www.postgresql.org/docs/current/static/datatype-numeric.html#DATATYPE-SERIAL