【问题标题】:AWS Redshift Identity Column Insert - New Records' Identity Value Not Greater Than Previous Max Identity ValueAWS Redshift 身份列插入 - 新记录的身份值不大于以前的最大身份值
【发布时间】:2019-06-25 07:05:12
【问题描述】:

这是我在 stackoverflow 上的第一篇文章!如果我未能正确遵守“提问”政策,请允许我在此直接道歉。

话虽如此,我在 AWS Redshift 中遇到了与以下帖子相关的“身份”列的问题,但问题不同:

Identity Column not respected on Insert into() (Amazon Redshift)

问题(下面提供的示例值是“只是示例”,以说明问题): “如果我有一个max(identityColumn) = 100,对于一个有100条记录的表,为什么我以后插入的新记录的identityColumn值不会大于100?”

预期结果: 如果我在新表中插入 5 条新记录,identityColumn 的值将是“101”、“102”、“103”、“104”、“105”

实际结果: 新记录的值为“52”、“57”、“62”...

如果我从上面粘贴的帖子中理解正确,身份列可能并不总是按顺序或连续顺序...这没关系。但是,我面临的问题是当我尝试插入新记录时,标识列没有从最后一个“最大”标识值继续。

以下是正在使用的代码类型的小示例:

---示例 1---

--1。使用标识列创建新表

CREATE TABLE newTable_With_Identity

( identityColumn bigint IDENTITY(1,1) ,column1 ,column2 ,column3 ,column4 ,column5 );

--2。将旧表中的数据插入新的标识表中

INSERT INTO newTable_With_Identity

( column1 ,column2 ,column3 ,column4 ,column5 ) (Select * from oldtable order by column3 asc);

---示例 2---

(同上,只是把最后一个select语句改成如下)

(Select * from oldtable order by column1, column2, column3 asc);

【问题讨论】:

    标签: sql amazon-redshift identity


    【解决方案1】:

    来自 Redshift 的文档:

    为确保身份值是唯一的,Amazon Redshift 在创建身份值时会跳过一些值。标识值是唯一的,但顺序可能与源文件中的顺序不匹配。

    来源:https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-26
      • 2016-02-02
      • 1970-01-01
      • 2020-02-12
      • 1970-01-01
      • 2022-08-10
      • 2013-09-30
      • 2012-09-28
      相关资源
      最近更新 更多