Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Impala SQL equivalent function of NEXTDAY in Netezza?

I have a SELECT statement that I am trying to convert from Netezza SQL to Impala SQL. The output looks something like 140612, which is a date that is obtained by subtracting 7 from the current date and then pulling out the monday of that week.

I need to have this readable for Impala, then format it, then turn it into a string.

The query is :

TO_CHAR(next_day(DATE(a.date)-7, 'Monday'), 'YYMMDD') AS START_DATE
like image 347
sreedivya Avatar asked Dec 11 '25 12:12

sreedivya


1 Answers

Assuming a.date is a timestamp, and T is the day of the week (1 = Sunday, 7 = Saturday; for your example above, Monday = 2, so T = 2) you should be able to use use

date_add(a.date, 7 - pmod(dayofweek(a.date) - T, 7));

in place of next_day in the above query. Check out the documentation on Impala's built-in date and time functions for more detail.

like image 99
Jeff Hammerbacher Avatar answered Dec 14 '25 09:12

Jeff Hammerbacher