【问题标题】:Redshift: creating a table with Timestamp column defaulting to Now()Redshift:创建一个时间戳列默认为 Now() 的表
【发布时间】:2016-04-07 19:46:08
【问题描述】:

有没有办法创建一个时间戳列默认为现在的表?

以下任何一项在创建时成功但在插入时失败。

CREATE TABLE MyTable
(
device_id         VARCHAR(64) NOT NULL encode lzo,
app_id            VARCHAR(150) NOT NULL distkey encode lzo,
retrieval_date    TIMESTAMP without time zone default (now() at time zone 'utc') encode lzo
)
diststyle key
compound sortkey(app_id,device_id);

然后插入:

     insert into MyTable (device_id,app_id) values('a','b');
INFO:  Function "timezone(text,timestamp with time zone)" not supported.
INFO:  Function "now()" not supported.
ERROR:  Specified types or functions (one per INFO message) not supported on Redshift tables.

我尝试了以下其他口味,但都失败了。

a) 用单引号 'now' 尝试 now ,创建成功但因另一个错误而失败

b) 尝试不带时区,创建成功,插入失败。

【问题讨论】:

    标签: sql amazon-redshift


    【解决方案1】:

    您可以使用SYSDATEGETDATE() 来放置当前时间戳值。这是一个例子。

    dev=> create table my_table (id int, created_at datetime default sysdate);
    CREATE TABLE
    
    dev=> insert into my_table (id) values (1);
    INSERT 0 1
    
    dev=> select * from my_table;
     id |        created_at
    ----+---------------------------
      1 | 2016-01-04 19:07:14.18745
    (1 row)
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    • 2016-12-19
    • 2012-11-30
    • 2016-03-28
    • 2013-06-20
    • 2018-01-13
    • 1970-01-01
    相关资源
    最近更新 更多