LoginSignup
3
1

More than 3 years have passed since last update.

Athena の TIMESTAMP は、 yyyy-MM-dd HH:mm:ss を直接サポートしない

Posted at

現象

Athena の TIMESTAMP は、よくある日付形式 yyyy-MM-dd HH:mm:ssを直接サポートしません。
例えば以下のようなCSVファイルからGlueでテーブルを作り、2番めのカラムの型にtimestampを設定したとします。

sample.csv
1000,2020-05-27 10:58:00
1001,2020-05-28 10:58:00

ここで、 select * from sample を実行してもエラーになります。おそらくこんなエラーメッセージが出ます。

HIVE_BAD_DATA: Error parsing field value '2020-05-27 10:58:00' for field 4: For input string: "2020-05-27 10:58:00"

対策

対策は、テーブルのカラム定義ではstringとして、読むときに date_parse 関数を使うことです。
date_by_stringは、2番めのカラム名だと思ってください。

sample.sql
select date_parse(date_by_string,'%Y-%m-%d %H:%i:%s') from sample

参考リンク

3
1
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
3
1