Re: Function fixing - PostgreSQL 9.2

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Function fixing - PostgreSQL 9.2
Date: 2016-03-01 01:23:39
Message-ID: CAKFQuwbNRQK5MX+vAqWY5OV0vZYF8+=qzsRO2_3CS3r=E7u8wQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Feb 29, 2016 at 6:14 PM, drum(dot)lucas(at)gmail(dot)com <drum(dot)lucas(at)gmail(dot)com>
wrote:

>
>
> On 1 March 2016 at 11:35, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
> wrote:
>
>> On Mon, Feb 29, 2016 at 2:56 PM, drum(dot)lucas(at)gmail(dot)com <
>> drum(dot)lucas(at)gmail(dot)com> wrote:
>>
>>> *Question:*
>>>
>>> Payments in a Pending state cannot be invoiced and are excluded from the
>>> Invoice Runs section, but they are showing in the count mechanic.
>>>
>>> How can I solve this?
>>>
>>
>> ​In 9.2 you probably need to convert the count into a conditional sum:
>>
>> SELECT sum(CASE WHEN <boolean> THEN 1 ELSE 0 END) FROM data;
>>
>> You can probably do the same with count since it excludes nulls.
>>
>> SELECT count(NULLIF(invoice_status, 'Pending') FROM invoices;
>>
>> ​9.4 introduced a FILTER clause for Aggregate Expressions that can do
>> this much more cleanly and efficiently.​
>>
>> ​http://www.postgresql.org/docs/9.4/static/sql-expressions.html​
>>
>> David J.
>>
>>
> Thank you David...
>
> Can you please show me how it would be with the new changes?
>
>
​I barely scanned your original query - just read the description. I don't
have the inclination - especially without a self-contained example - to
make changes to it.

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rafal Pietrak 2016-03-01 07:04:15 Re: multiple UNIQUE indices for FK
Previous Message drum.lucas@gmail.com 2016-03-01 01:14:10 Re: Function fixing - PostgreSQL 9.2