doc说Expressions on base columns
的支持聚类,并具有将to_date(Timestamp)用作群集键的示例,
https://docs.snowflake.net/manuals/user-guide/tables-micro-partitions.html#defining-clustering-clustering-keys-for-a-a-a-a-table
确实在我验证的情况下确实有效,但是就我而言,按小时群集更好,因此将date_trunc按小时用作cluster键
CREATE OR REPLACE TABLE t(
"timestamp" datetime,
... more fields
) CLUSTER BY (DATE_TRUNC('HOUR', "timestamp"));
创建表可以成功运行,但是,当将数据加载到副本中时,它说在副本中不支持,所以奇怪的是按照支持的小时聚类吗?还是复制命令的限制?有人知道解决方法吗?
002300 (0A000): SQL Compilation error: Function 'TRUNCTIMESTAMPTOHOUR'
not supported within a COPY
在Stuart的答案上扩展:只需在[登台区域]进行插入。
。INSERT INTO DB.SCHEMA.T(timestamp, col2, ...)
SELECT
$1::timestamp_ntz,
$2
...
FROM
@SOURCE.EXTRACTS/folder_location (FILE_FORMAT => '[file_format_name]',
PATTERN => '[regex file pattern]')
作为解决方法,尝试将未定义的群集键复制到登台表" stg"。然后插入目标表:
INSERT INTO t
SELECT * FROM stg
ORDER BY (DATE_TRUNC('HOUR', "timestamp"));