在Snowflake的创建脚本中添加当前日期 [英] Adding current date in create script for Snowflake

查看:208
本文介绍了在Snowflake的创建脚本中添加当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,当动态创建表时,必须创建表名称为date/datetime的表.想知道在Snowflake中是否可以使用此选项吗?

I have a requirement where I have to create tables with the date/datetime in the table name when they were created dynamically.Wondering if this option is possible in Snowflake?

例如: 我需要这样的东西.

Eg: I would need somethinglike this.

创建表someNewTable_YYYYMMDD

感谢您的回复;

最好, AB

推荐答案

您可以使用

You can achieve this using SQL variables and the IDENTIFIER keyword.

下面是一个将当前日期添加到表名的示例:

Here's an example that adds the current date into the table-name:

SET table_name=(SELECT 'someNewTable_' || TO_VARCHAR(CURRENT_DATE(), 'YYYYMMDD'));

CREATE TABLE IDENTIFIER($table_name) (col STRING);

对于使用IDENTIFIER关键字不足的更复杂的任务,您还可以使用存储过程

For more complicated tasks where using IDENTIFIER keyword is inadequate, you can also use stored procedures as shown in this answer.

这篇关于在Snowflake的创建脚本中添加当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆