no IF - am I missing something ? - Mailing list pgsql-general

From Richard Crawley
Subject no IF - am I missing something ?
Date
Msg-id opsnsserfhyivrd9@richardcgx270.zen.co.uk
Whole thread Raw
Responses Re: no IF - am I missing something ?
List pgsql-general
Hello all.

In the tail end of converting an app from MySQL to psql. I have this code :


<snip>
IF(days_complete <= -120, job_price,0) AS Days_120,
IF(days_complete BETWEEN -119 AND -90, job_price,0) AS Days_90,
IF(days_complete BETWEEN -89 AND -60, job_price,0) AS Days_60,
IF(days_complete BETWEEN -59 AND -30, job_price,0) AS Days_30,
IF(days_complete BETWEEN -29 AND 0, job_price,0) AS current
<snip>


It builds an aged debt report, and there are similar versions that SUM(IF ..) to give me debt by customer etc.

All the questions I've seen about IF end up with people saying "use CASE" and I'm sure it would work. But do you lot
reallyuse 5 lines for each IF ? Doesn't it seem kind of ugly ? Or do you all secretly write a quick IF function ? 

I'm interested, and I half suspect that I'm missing a more elegant solution.



thanks


Rich


pgsql-general by date:

Previous
From: Edgar Amorim
Date:
Subject: Install error at rpm package + Fedora Core3
Next
From: "Justin L. Kennedy"
Date:
Subject: Tsearch vector not stored by update/set