gpt4 book ai didi

sql - 我想在我现有的配置单元表中添加一个额外的列,以便我可以获得当天的当前时间戳

转载 作者:可可西里 更新时间:2023-11-01 16:35:24 29 4
gpt4 key购买 nike

需要在我现有的配置单元表中添加额外的日期列,以便它选择当天系统的当前日期

hive (hivejobs)>
select * from my_current_Table;
OK
name age
Aditya 2
Aditya 7

我想在此处添加一个日期列,以便我可以在添加列时立即获取当天的当前系统日期。我认为解决方法是将两个表与具有当前系统日期的其他表连接起来。

下面是我的代码和思考过程。

alter table my_current_Table add columns( todays_date current_date());

这给了我一个错误,我找不到真正的方法来做这件事

请帮忙。

预期输出

hive (hivejobs)> 
select * from my_current_Table;

OK
name age todays_date
Aditya 2 2019-02-08 13:21:50
Aditya 7 2019-02-08 13:21:50

最佳答案

您不能在 Hive 表中定义计算列。

如果你想一直查询今天的日期,在select中使用current_timestamp函数:

select t.*, 
date_format(current_timestamp,'yyyyMMdd HH:mm:ss') as todays_date
from my_current_Table t;

如果要添加列并存储插入记录的日期,请将列添加到表中并从自身重新加载,例如:

alter table my_current_Table  add columns(load_date string);

insert overwrite table my_current_Table
select t.*,
date_format(current_timestamp,'yyyyMMdd HH:mm:ss') as load_date
from my_current_Table t;

关于sql - 我想在我现有的配置单元表中添加一个额外的列,以便我可以获得当天的当前时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54600417/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com