首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用sysdate创建缺省列,但在插入数据时出现字符变化错误

使用sysdate创建缺省列,但在插入数据时出现字符变化错误
EN

Stack Overflow用户
提问于 2020-05-22 01:54:58
回答 1查看 102关注 0票数 0

我使用一个默认的sysdate列在redshift中创建了一个表,但是当我插入数据时,我得到了一个奇怪的表达式,它的类型是character varying。这是我第一次遇到这个错误。

代码语言:javascript
复制
CREATE TABLE IF NOT EXISTS shipments_swp
(
shipment_id                      bigint DISTKEY ENCODE RAW,
user_id                          bigint ENCODE ZSTD,
last_tracking_event_time         timestamp encode zstd,
bd_updated_at                    timestamp default sysdate ENCODE ZSTD
);

Insert into shipments_swp
(
select *
from common.shipments_dim
);

错误消息如下所示

代码语言:javascript
复制
SQL Error [500310] [42804]: [Amazon](500310) Invalid operation: column "bd_updated_at" is of type timestamp without time zone but expression is of type character varying;
EN

回答 1

Stack Overflow用户

发布于 2020-05-23 00:17:43

你能给出一个你想要插入到这个专栏中的时间戳的例子吗?在将其写入shipments_swp之前,您可能需要将该列转换为时间戳。我尝试了一个简单的测试,看看插入是否正确,插入没有任何问题:

代码语言:javascript
复制
CREATE TABLE IF NOT EXISTS test_table_a (
    ts_a    TIMESTAMP DEFAULT SYSDATE ENCODE ZSTD
);

-- Insert a few different date formats
insert into test_table_a values('2020/05/22');
insert into test_table_a values('2020-05-22');
insert into test_table_a values('2020-05-22 16:12:27.830728');
insert into test_table_a values('2020-05-22 16:06:00');

--- Create a second table and write to that 
--- to mimic the insert behavior from the question

CREATE TABLE IF NOT EXISTS test_table_b (
    ts_b    TIMESTAMP DEFAULT SYSDATE ENCODE ZSTD
);

INSERT INTO test_table_b (
    SELECT *
    FROM test_table_a
);

--- This insert succeeds
SELECT * FROM test_table_b;

2020-05-22 16:06:00
2020-05-22 00:00:00
2020-05-22 16:06:56.823844
2020-05-22 00:00:00
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61940769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档