0

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

ab_P
  • 1
  • 2

1 Answers1

2

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.