TO_TIMESTAMP 函數 - AWS Clean Rooms

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

TO_TIMESTAMP 函數

TO_TIMESTAMP 會將 TIMESTAMP 字串轉換為 TIMESTAMPTZ。

語法

to_timestamp (timestamp)
to_timestamp (timestamp, format)

引數

timestamp

時間戳記字串或可轉換為時間戳記字串的資料類型。

format

符合 Spark 日期時間模式的字串常值。如需有效的日期時間模式,請參閱格式化和剖析的日期時間模式

傳回類型

TIMESTAMP

範例

下列範例示範如何使用 TO_TIMESTAMP 函數將 TIMESTAMP 字串轉換為 TIMESTAMP。

select current_timestamp() as timestamp, to_timestamp( current_timestamp(), 'YYYY-MM-DD HH24:MI:SS') as second; timestamp | second -------------------------- ---------------------- 2021-04-05 19:27:53.281812 | 2021-04-05 19:27:53+00

可以傳遞日期的 TO_TIMESTAMP 部分。其餘日期部分設定為預設值。時間包含在輸出中:

SELECT TO_TIMESTAMP('2017','YYYY'); to_timestamp -------------------------- 2017-01-01 00:00:00+00

下列 SQL 陳述式會將字串 '2011-12-18 24:38:15' 轉換為 TIMESTAMP。結果是 TIMESTAMP 落在第二天,因為時數超過 24 小時:

select to_timestamp('2011-12-18 24:38:15', 'YYYY-MM-DD HH24:MI:SS'); to_timestamp ---------------------- 2011-12-19 00:38:15+00