Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How avoid – User defined aggregate cannot be used in query with other distinct aggregates

I have error

[0A000][5366] [Vertica]VJDBC ERROR: User defined aggregate cannot be used in query with other distinct aggregates

when I execute

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT LISTAGG(DISTINCT a USING PARAMETERS separator=',', max_length = 10) AS a,
       COUNT(DISTINCT b)                                                   AS b
FROM t

Do I have a way to avoid this aggregation and have the same logic?

In real project I have a complex query with many "subselect" and "with as", "group by" logic, so I wonder how it is possible to refactor, how many way I have?

I read the links, but no ideas how combine COUNT DISTINCT and LISTAGG DISTINCT: https://www.vertica.com/docs/9.2.x/HTML/Content/Authoring/SQLReferenceManual/Functions/Aggregate/COUNTAggregate.htm
https://www.vertica.com/docs/9.3.x/HTML/Content/Authoring/SQLReferenceManual/Functions/Aggregate/LISTAGG.htm

DB: Vertica Analytic Database v10.1.1-3

>Solution :

You could use sub-queries to do the distinct.

SELECT LISTAGG(aa.a USING PARAMETERS separator=',', max_length = 10) AS a,
       COUNT(bb.b)                                                   AS b
FROM 
  (SELECT DISTINCT a FROM t) aa,
  (SELECT DISTINCT b FROM t) bb;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading