Why returns this query 'date_parse(Openingsdatum, '%d-%m-%Y' )' more information then just the day, month and year ?

0

Hi all,

If I run this query:

SELECT date_parse(Openingsdatum, '%d-%m-%Y') Openingsdatum , date_parse(REPLACE(Einddatum, '', NULL), '%d-%m-%Y') Einddatum

I get different errors. First af all, I'm wondering why the output for the openingsdatum is more then the day, month and year. It also included the timestamp: 2022-09-07 00:00:00.000. How can I remove this?

Also, the 'Einddatum' doesn't work either. I found out that I can only convert the string into a dateformat if there are now blank cells. So I tried to do it with the replace function but this doesn't work. I get the error: INVALID_FUNCTION_ARGUMENT: Invalid format: ""

質問済み 2年前251ビュー
1回答
0
承認された回答

It is an expected output from date_parse which "parses timestamps"/"returns a timestamp" please follow this presto documentation : https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions.

You can use this query to truncate the time part from timestamp.

select Date(date_parse('2022-03-01','%Y-%m-%d'))

Also please note that Athena for DML queries uses presto for query execution. So in order to write a DML query upto Athena standards we have to use presto functions only.

Here date_parse() expects a string argument and parses that into timestamp format. Now as you stated that you also have null values. Here I have one question, are these empty values is in the form of "" or null in your table, Because if the empty values are in the form of 'null' then the date_parse should work perfectly fine. Like below:

select Date(date_parse(null,'%Y-%m-%d'))

But this will not :

select Date(date_parse('','%Y-%m-%d'))

because on seeing string '' it performs parsing only to find it is not in the standard format and throws error INVALID_FUNCTION_ARGUMENT: Invalid format: ""

In order to make it work you can use this query

select CASE date_g
           WHEN '' THEN null
           ELSE Date(date_parse(date_g,'%Y-%m-%d'))
       END 
FROM Table_name
AWS
サポートエンジニア
Shubh
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ