{code} curl -X POST http://localhost:8080/pdb/query/v4 2>/dev/null \ -H 'Content-Type:application/json' \ -d '{"query": "inventory[facts.osfamily, count()]{ group by facts.osfamily }" }' {code}
Produces the SQL {code} 2021-08-02 16:36:18,728 INFO [qtp90455758-58] [p.p.query-eng] PDBQuery:b1e56636-dc83-45c4-8943-90620ec4d2d1:["WITH inactive_nodes AS (SELECT certname FROM certnames WHERE (deactivated IS NOT NULL AND deactivated > '2021-07-19T23:36:18.728Z') OR (expired IS NOT NULL and expired > '2021-07-19T23:36:18.728Z')), not_active_nodes AS (SELECT certname FROM certnames WHERE (deactivated IS NOT NULL OR expired IS NOT NULL)) SELECT (fs.stable||fs.volatile)->'osfamily' AS \"facts.osfamily\", count(*) count FROM factsets fs LEFT JOIN environments ON fs.environment_id = environments.id LEFT JOIN certnames ON fs.certname = certnames.certname WHERE NOT ((certnames.certname) in (SELECT certname FROM ( SELECT not_active_nodes.certname AS \"certname\" FROM not_active_nodes ) sub)) GROUP BY (fs.stable||fs.volatile)"] {code}
but the {{GROUP BY}} filter is wrong. Instead of the `:field` value of the requested {{facts.osfamily}}, it should be the projection name, surrounded by double quotes.
The correct SQL would look like {code} WITH inactive_nodes AS (SELECT certname FROM certnames WHERE (deactivated IS NOT NULL AND deactivated > '2021-07-19T23:36:18.728Z') OR (expired IS NOT NULL and expired > '2021-07-19T23:36:18.728Z')), not_active_nodes AS (SELECT certname FROM certnames WHERE (deactivated IS NOT NULL OR expired IS NOT NULL)) SELECT (fs.stable||fs.volatile)->'osfamily' AS "facts.osfamily", count(*) count FROM factsets fs LEFT JOIN environments ON fs.environment_id = environments.id LEFT JOIN certnames ON fs.certname = certnames.certname WHERE NOT ((certnames.certname) in (SELECT certname FROM ( SELECT not_active_nodes.certname AS "certname" FROM not_active_nodes ) sub)) GROUP BY "facts.osfamily"; {code}
Austin Blatt where can we get our hands on a server with this fix? Lynsay Wright has made a fix in the ER Query Service and needs to verify it against the latest fix, before we cut a new release and hand it over to Chris Leicester for a CD4PE release.