Datetime 데이터 타입

Snowflake의 데이터 타입과 함수

Jake Roach

Field Data Engineer

DATE 데이터 타입

  • Date 값은 어떤 일이 발생한 날짜를 저장합니다
                            2023-04-01
                            YYYY-MM-DD
  CREATE TABLE sales (
      transaction_date DATE  -- Define a column of type `DATE`
  );
Snowflake의 데이터 타입과 함수

DATE 데이터 타입

SELECT

TO_DATE('2023-04-01') AS the_date, -- Convert a string into a DATE
'2023-04-01'::DATE AS casted_date -- Casted using <value>::DATE
;
                         the_date  | casted_date  
                       ----------- | ------------  
                        2023-04-01 | 2023-04-01
Snowflake의 데이터 타입과 함수

Time 데이터 타입

  • 어떤 이벤트가 발생한 시·분·초를 저장합니다
                               08:24:08
                               HH:MM:SS
CREATE TABLE sales (
    transaction_time TIME  -- Create a column with the `TIME` keyword
);
  • TIME 열 정의
Snowflake의 데이터 타입과 함수

Time 데이터 타입

SELECT

TO_TIME('08:24:04') AS the_time,
'08:24:04'::TIME AS casted_time
;
                     |  the_time  | casted_time |
                     | ---------- | ----------- |
                     |  08:24:08  |  08:24:08   |
  • TO_TIME 함수
  • ::로 캐스팅
Snowflake의 데이터 타입과 함수

Timestamp 데이터 타입

  • TIMESTAMP는 날짜와 시간을 모두 포함합니다
                        2023-04-01 08:24:04
                        YYYY-MM-DD HH:MM:SS
CREATE TABLE (
    transaction_timestamp TIMESTAMP
);
Snowflake의 데이터 타입과 함수

Timestamp 데이터 타입

SELECT 
    TO_TIMESTAMP('2023-04-01 08:24:04') AS the_timestamp,
    '2023-04-01 08:24:04'::TIMESTAMP AS casted_timestamp          
;
  • 문자열을 TO_TIMESTAMP 또는 <value>::TIMESTAMP로 변환
  • 날짜·시간 저장의 가장 일반적 방식
                  the_timestamp     |    casted_timestamp     
              --------------------- | ----------------------  
               2024-04-01 08:24:08  |  2024-04-01 08:24:08    
Snowflake의 데이터 타입과 함수

예시

SELECT
    TO_DATE('2021-05-14') AS the_date,
    TO_TIME('06:13:00') AS the_time,
    TO_TIMESTAMP('2021-05-14T06:13:00') AS the_timestamp,


-- Extract the DATE from a TIMESTAMP, we could do the same with TIME! transaction_timestamp::DATE AS casted_date
;
           the_date   |   the_time  |     the_timestamp    | casted_date  
         ------------ | ----------- | -------------------- | ------------  
          2021-05-14  |   06:13:00  | 2021-05-14T06:13:00  |  2021-05-14
Snowflake의 데이터 타입과 함수

타임존

기본적으로 DATE, TIME, TIMESTAMP는 타임존 없이 저장됩니다

$$

TIMESTAMP_NTZ

  • TIMESTAMP의 기본 구현
  • 타임존을 저장하지 않음

$$

TIMESTAMP_LTZ

  • 로컬 타임존 사용

$$

TIMESTAMP_TZ

  • 사용자가 타임존을 지정
1 https://docs.snowflake.com/en/sql-reference/data-types-datetime#timestamp-ltz-timestamp-ntz-timestamp-tz
Snowflake의 데이터 타입과 함수

연습해 봅시다!

Snowflake의 데이터 타입과 함수

Preparing Video For Download...