On 26/07/18 20:31, Tom Lane wrote: > matshyeq <matsh...@gmail.com> writes: >> Can I make custom aggregate function that accepts WITHIN GROUP syntax? > > It's possible, but it would have to be written in C, I think; see > src/backend/utils/adt/orderedsetaggs.c for prototype code. You'll > find it a lot easier to write a plain aggregate function and control > its input ordering with "last(foo order by foo)".
We have examples on the wiki. https://wiki.postgresql.org/wiki/First/last_(aggregate) -- Vik Fearing +33 6 46 75 15 36 http://2ndQuadrant.fr PostgreSQL : Expertise, Formation et Support