goqu icon indicating copy to clipboard operation
goqu copied to clipboard

window function postgres filter

Open talpa opened this issue 5 years ago • 1 comments

Hi great author:) Dialect

  • [ ] postgres how make filter for this window function?, for example SUM(adi.amount) FILTER (WHERE ad.document_status = 'pending') as unpaid_document_sum

Thanks Ales

talpa avatar Feb 20 '20 09:02 talpa

You could put the whole thing in a literal

db.From("x").Select(goqu.L(`SUM(adi.amount) FILTER (WHERE ad.document_status='pending')`)).As("unpaid_document_sum")
SELECT SUM(adi.amount) FILTER (WHERE ad.document_status='pending') 
FROM "x"

Frug avatar Nov 01 '20 21:11 Frug