LoginSignup
4
3

More than 5 years have passed since last update.

Redshift でセッション内 timezone を指定するたった1つの冴えないやり方

Last updated at Posted at 2014-06-09

Redshiftのシステム時刻はUTC固定かつ(セッション内であっても)変更不可

mydb=# show timezone;
 TimeZone
----------
 UTC
(1 row)

mydb=# set session timezone='Asia/Tokyo';
ERROR:  tried to set timezone to Asia/Tokyo
DETAIL:  Not user settable.
mydb=# set local timezone='Asia/Tokyo';
ERROR:  tried to set timezone to Asia/Tokyo
DETAIL:  Not user settable.

のはずなのだけど...

これを見て欲しい。

$ date ; psql -h redshift.somerandom.ap-northeast-1.redshift.amazonaws.com -U admin mydb -c "select now()"
2014年 6月 9日 月曜日 20時23分35秒 JST
              now
-------------------------------
 2014-06-09 20:23:38.011287+09
(1 row)

JSTになってますね!

どうやってるの?

postgresユーザなら知ってる人もいるかもしれませんが、PGTZ環境変数を設定すると、timezoneが設定できてしまいます。

$ PGTZ="Asia/Tokyo" psql -h redshift.somerandom.ap-northeast-1.redshift.amazonaws.com -U admin mydb -c "select now()"
              now
-------------------------------
 2014-06-09 20:26:55.768399+09
(1 row)

$ PGTZ="America/New_York" psql -h redshift.somerandom.ap-northeast-1.redshift.amazonaws.com -U admin mydb -c "select now()"
              now
-------------------------------
 2014-06-09 07:27:04.316516-04
(1 row)

$ PGTZ="America/Los_Angeles" psql -h redshift.somerandom.ap-northeast-1.redshift.amazonaws.com -U admin mydb -c "select now()"
              now
-------------------------------
 2014-06-09 04:27:17.164795-07
(1 row)

pgAdmin3(そもそも古めのバージョンじゃないとダメですが)でも、下記のように起動するとJSTで使えます。

$ PGTZ='Asia/Tokyo' open /Applications/pgAdmin3.app/

ところがどっこい

mydb=# select now() as time1 into newtable;
ERROR:  Column "time1" has unsupported type "timestamp with time zone".

ガーン、だな。"timestamp with time zone"なカラムが作成できないんじゃ、実質使い道がない。

以上、ネタ投稿でした。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3