问题
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