시각 관련 data query를 작성할 때, 최종 결과물을 눈으로 확인할 때 datetime과 timestamp가 비슷한 것 같은데 DB엔진에서는 서로 다르게 인식하는 것 같아서 그 차이를 알아보고 정리해 보았다.
select
current_timestamp() eg_timestamp,
current_datetime() eg_datetime
timestamp는 value 말미에 'UTC'라고 적혀있고,
datetime은 value 중간에 'T'라고 적혀있다.
먼저, UTC에 대해서 알아보기( 출처: 위키피디아 )
→ 쉽게 말해, UTC는 어디에서든 같은 시각을 인지할 수 있게 시각을 표현하는 기준이다. 같은 15시라도 뉴욕에서의 15시와 서울에서의 15시는 동시에 존재할 수 없기 때문이다.
bigquery에서는 timezone( 시차 )에 맞춰서 시각을 표현할 수 있는데,
이에 대해 다시 표현 해 보면...
select
current_timestamp() eg_timestamp,
timestamp( '2021-07-04' ) timestamp_value_example,
timestamp( '2021-07-04', 'Asia/Seoul' ) timestamp_value_example_seoul,
current_datetime() eg_datetime,
datetime( '2021-07-04' ) datetime_value_example,
datetime( '2021-07-04', 'Asia/Seoul' ) datetime_value_example_seoul,
datetime은 Timezone이 지정되어도 어느 Timezone을 기준으로 한 value인지 알 수 없다.
반면, Timestamp는 해당 Timezone을 기준으로, 그 떄의 UTC 시각을 알 수 있다.
위의 차이가 있다.
이 밖에도,
등등이 있지만, 가장 중요한 차이는 전술한 Timezone을 알 수 있다는 여부이지 않을까