Hi, we are trying to integrate GMDA algorithm into postgresql. The operater decouples grouping from aggregation and we came up with the following syntax:
SELECT d, u, COUNT(*b.u <= r.u*) AS ccu, COUNT(*b.d <= r.d*) AS ccd FROM b *GMDJOIN* r GROUP BY d, u This select query should be rewritten to: WITH xi AS ( SELECT d, u SUM(COUNT(*)) OVER (PARTITION BY u) AS ccu, SUM(COUNT(*)) OVER (PARTITION BY d) AS ccd FROM r GROUP BY d, u ), x1 AS ( SELECT b1.u, SUM(ccu) AS ccu FROM (SELECT DISTINCT u FROM xi) b1 LEFT OUTER JOIN (SELECT DISTINCT u, ccu FROM xi) xi1 ON xi1.u = b1.u GROUP BY b1.u ), x2 AS ( SELECT b2.d, SUM(ccd) AS ccd FROM (SELECT DISTINCT d FROM xi) b2 LEFT OUTER JOIN (SELECT DISTINCT d, ccd FROM xi) xi2 ON xi2.d = b2.d GROUP BY b2.d ) SELECT * FROM x1 NATURAL JOIN x2 ORDER BY d,u Now to our question: Can this be integrated into the postresql QueryRewrite function? Should that be integrated into the rewrite stage of the postgresql kernel or should the rewrite action be done somewhere else? Is there any tutorial on rewriting statements? Thank you very much for your time and help, Andi -- View this message in context: http://postgresql.1045698.n5.nabble.com/Adding-rewrite-rule-to-QueryRewrite-tp5738481.html Sent from the PostgreSQL - hackers mailing list archive at Nabble.com. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers