Adding current date in create script for Snowflake

流过昼夜 提交于 2020-06-29 05:24:50

问题


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.

CREATE TABLE someNewTable_YYYYMMDD

Thank you for your responses;

Best, AB


回答1:


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);

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



来源:https://stackoverflow.com/questions/62294255/adding-current-date-in-create-script-for-snowflake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!