pg icon indicating copy to clipboard operation
pg copied to clipboard

Add support for window functions

Open blastrock opened this issue 4 years ago • 0 comments

Hello,

It would be nice to have support for PostgreSQL's window functions in go-pg.

They take two forms:

SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname)
FROM empsalary;

-- or

SELECT depname, empno, salary, avg(salary) OVER w
FROM empsalary
WINDOW w AS (PARTITION BY depname);

The first form is already usable with ColumnExpr("avg(salary) OVER (PARTITION BY depname)"). The second is not (AFAIK).

The second form is useful when you want to compute multiple columns from a single window, like min(salary) OVER w, avg(salary) OVER w. It would help me if go-pg supported a syntax like .Window("w AS (PARTITION BY depname)").

blastrock avatar Feb 12 '21 14:02 blastrock