简体   繁体   English

Redshift 将日期值插入表中

[英]Redshift insert a date value into a table

insert into table1 (ID,date)
select
ID,sysdate 
from table2

assume i insert a record into table2 with value ID:1,date:2023-1-1 the expected result is update the ID of table1 base on the ID from table2 and update the value of date of table1 base on the sysdate from table2.假设我向表 2 中插入一条记录,其值为 ID:1,日期:2023-1-1 预期结果是根据表 2 中的 ID 更新表 1 的 ID,并根据表 2 中的 sysdate 更新表 1 的日期值。

select * 
from table1;

the expected result after running the insert statement will be运行插入语句后的预期结果将是

ID ID date日期
1 1个 2023-1-6 2023-1-6

but what i get is:但我得到的是:

ID ID date日期
1 1个 2023-1-1 2023-1-1

I see a few possibilities based on the information given:根据给出的信息,我看到了一些可能性:

  1. You say "the expected result is update the ID of table1 base on the ID from table2" and this begs the question - did ID = 1 exist in table1 BEFORE you ran the INSERT statement?您说“预期结果是根据 table2 的 ID 更新 table1 的 ID”,这引出了一个问题 - 在您运行 INSERT 语句之前,id = 1 是否存在于 table1 中? If so are you expecting that the INSERT will update the value for ID #1?如果是这样,您是否期望 INSERT 将更新 ID #1 的值? Redshift doesn't enforce or check uniqueness of primary keys and you would get 2 rows in the table1 in this case. Redshift 不强制或检查主键的唯一性,在这种情况下,您会在 table1 中获得 2 行。 Is this what is happening?这是怎么回事?
  2. SYSDATE on Redshift provides the start timestamp of the current transaction, NOT the current statement. Redshift 上的 SYSDATE 提供当前事务的开始时间戳,而不是当前语句。 Have you had the current transaction open since the 1st?您是否从 1 日起就开始了当前交易?
  3. You didn't COMMIT the results (or the statement failed) and are checking from a different session. It could also be that the transaction started before in the second session before the COMMIT completed.您没有提交结果(或语句失败)并且正在从不同的 session 进行检查。也可能是事务在 COMMIT 完成之前的第二个 session 之前开始。 Working with MVCC across multiple sessions can trip anyone up.跨多个会话使用 MVCC 可能会绊倒任何人。

There are likely other possible explanations.可能还有其他可能的解释。 If you could provide DDL, sample data, and a simple test case so that others can recreate what you are seeing it would greatly narrow down the possibilities.如果您可以提供 DDL、示例数据和一个简单的测试用例,以便其他人可以重新创建您所看到的内容,那将大大缩小可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM