【问题标题】:ID of the transaction that inserted a row on Amazon Redshift在 Amazon Redshift 上插入行的事务的 ID
【发布时间】:2016-09-28 22:56:37
【问题描述】:

我需要知道插入行的事务的 ID。

在香草 postgres 上我可以做到:

SELECT xmin from <table>

但在 Redshift 上:

ERROR: column xmin does not exist in <table>

有没有办法得到我需要的东西?

【问题讨论】:

    标签: postgresql amazon-redshift


    【解决方案1】:

    由于默认情况下 Redshift 中没有自动递增的列,我会说用额外的列重新创建该表。该新列应该是 IDENTITY 列。您不应在该列中插入任何内容。每次插入一行时,它将自动增量填充。它对于每一行都是唯一的,因此您可以将该列用作 row_id。

    你的 DDL 应该是这样的:

    CREATE TABLE <schema>.<table_name>
    (
        row_id BIGINT IDENTITY (0,1),
        ....
    )
    

    现在将旧表中的行插入其中。同样,不要为 row_id 列分配任何值。 (它会给你一个错误)你会看到它是自动填充的。

    【讨论】:

      猜你喜欢
      • 2018-09-19
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-23
      • 1970-01-01
      • 1970-01-01
      • 2014-10-16
      相关资源
      最近更新 更多