Trino 는 세션 타임존을 기준으로 시각을 해석하고 출력한다. 서버 OS 의 타임존과는 별개다.
SELECT current_timezone();
SELECT current_timestamp;
SELECT now();
now() 는 current_timestamp 의 별칭이고 둘 다 timestamp(3) with time zone 을 돌려준다. 서버 쪽 OS 타임존이 궁금하다면 그건 SQL 이 아니라 서버에서 본다.
timedatectl
SET TIME ZONE 'UTC';
SET TIME ZONE 'Asia/Seoul';
SET TIME ZONE LOCAL;
SET SESSION time_zone = ... 이라는 문법은 없다. 타임존은 전용 문장인 SET TIME ZONE 으로 바꾼다. 접속 시점에 정하려면 클라이언트 쪽에서 준다.
trino --server https://trino.example.net:8443 --timezone Asia/Seoul
JDBC 라면 드라이버가 JVM 기본 타임존을 쓰므로 -Duser.timezone=Asia/Seoul 로 맞추거나 커넥션 속성으로 지정한다.
Trino 에는 Hive·Impala 의 unix_timestamp() 가 없다. 이름이 다른 함수를 쓴다.
| 목적 | Hive · Impala | Trino |
|---|---|---|
| 현재 epoch 초 | unix_timestamp() |
to_unixtime(current_timestamp) |
| timestamp → epoch 초 | unix_timestamp(ts) |
to_unixtime(ts) |
| epoch 초 → timestamp | from_unixtime(n) |
from_unixtime(n) |
| 문자열 → timestamp | unix_timestamp(s, fmt) |
date_parse(s, fmt) |
SELECT to_unixtime(current_timestamp);
SELECT from_unixtime(1727077384);
SELECT from_unixtime(1727077384, 'Asia/Seoul');
to_unixtime 은 double 을 돌려주므로 소수부가 붙는다. 초 단위 정수가 필요하면 캐스팅한다.
SELECT CAST(to_unixtime(current_timestamp) AS bigint);
from_unixtime(n) 의 결과는 세션 타임존으로 해석된다. 세션 타임존이 다르면 같은 숫자가 다른 시각으로 보이므로, 엔진을 오가며 비교할 때는 타임존을 먼저 맞춘다.
Impala 와 Hive 에는 use_local_tz_for_unix_timestamp_conversions 플래그가 있다. 기본값 false 에서는 epoch 변환을 UTC 기준으로 하고, true 로 켜면 로컬 타임존을 반영한다. 같은 epoch 값이 Impala 와 Trino 에서 9시간 차이로 보인다면 대개 이 플래그와 Trino 세션 타임존이 어긋난 것이다.
Trino 에는 이 플래그에 해당하는 설정이 없다. Trino 쪽은 오직 세션 타임존으로만 결정되므로, 엔진마다 다음을 맞춰 준다.
| 엔진 | 맞출 것 |
|---|---|
| Impala · Hive | use_local_tz_for_unix_timestamp_conversions |
| Trino | SET TIME ZONE 또는 클라이언트 --timezone |
비교할 때는 양쪽에서 같은 리터럴을 변환해 보고 결과를 대조하면 어느 쪽이 어긋났는지 바로 드러난다.
SELECT to_unixtime(TIMESTAMP '2026-01-01 00:00:00');