目次
やり方
Redshiftでこのような形でUNIX秒のカラムがあったら、次のようにしてタイムスタンプ型に変換します。
| created_at |
|---|
| 1586271600 |
| 1591607652 |
| 1591542000 |
| 1593529199 |
| 1609426799 |
UNIX秒をタイムスタンプ型に変換するSQL
select
created_at
,convert_timezone('jst', timestamp 'epoch' + cast(created_at as bigint) * interval '1 second') as formatted_created_at
from table_name出力結果
| created_at | formatted_created_at |
|---|---|
| 1586271600 | 2020-04-08 00:00:00 |
| 1591607652 | 2020-06-08 18:14:12 |
| 1591542000 | 2020-06-08 00:00:00 |
| 1593529199 | 2020-06-30 23:59:59 |
| 1609426799 | 2020-12-31 23:59:59 |
補足
UNIX時間にはマイクロ秒で記載していることもあります。 その場合は1000で割ります。
select
convert_timezone('jst', created_at
,timestamp 'epoch' + cast(created_at as bigint) / 1000 * interval '1 second') as formatted_created_at
from table_name