GROUPING() on current time in HAVING clause in subquery and outer query grouping
Hello!
This topic is based on the relevant SO question: https://stackoverflow.com/q/48869357/1220930
In short, the following query fails with strange error message:
SELECT * FROM ( SELECT DATEDIFF('year', event_timestamp, NOW()) FROM events GROUP BY CUBE( DATEDIFF('year', event_timestamp, NOW()) ) HAVING GROUPING( DATEDIFF('year', event_timestamp, NOW()) ) = 0 ) AS subqueries GROUP BY 1;
[42803][7182] [Vertica]VJDBC ERROR: Grouping function arguments need to be group by expressions
But argument of the GROUPING
is same with GROUP BY
and NOW()
is stable function. Solution is to wrap the NOW()
in the extra subquery. More details are in linked SO topic (should i copy it here?). The solution works, but looks like a bug workaround, so I just want to report and clarify it.
0
Best Answer
-
Jim_Knicely - Select Field - Administrator
Hi,
I opened a support ticket on this issue and will keep you updated on its progress.
Thanks for reporting this!
5
Answers
As proposed in the SO answer (https://stackoverflow.com/a/48878902/1220930), I replaced the
NOW()
by subquery(SELECT NOW())
. It works in most cases, but unfortunately in some cases it causes the following internal error:Restarting the query does not help. The minimal example query:
The query works fine when I replace
SELECT NOW()
by justNOW()
. Also it works when I remove first condition (byc.type
) in theHAVING
clause.Looks like it related with initial issue: something wrong with
NOW()
function in a grouping context. Hope this helps to fix this bug.One of my customers just upgraded to 8.1 and hitting this error. It works on their 7.1 environment. Any update on this yet? I am yet to look into the Cases.
Error: ERROR: Grouping function arguments need to be group by expressions
SQLState: 42803
ErrorCode: 0
Thanks,
Ramesh Narayanan
Vertica PS
@Ramesh,
This is fixed in Vertica 8.1.1-20.
See VER-62854:
https://my.vertica.com/docs/ReleaseNotes/8.1.x/Vertica_8.1.x_Release_Notes.htm#8.1.1-20