Re: isnull() function in pgAdmin3

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: dudedoe01 <marsalanaq(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: isnull() function in pgAdmin3
Date: 2016-10-03 21:36:50
Message-ID: CAKFQuwYe=mFh5JM8sqCpUKob_ittkGa-C=1hpAHoU=MA1SrGtw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Oct 3, 2016 at 6:39 AM, dudedoe01 <marsalanaq(at)gmail(dot)com> wrote:

> What is the most feasible way to emulate the below MySQL function into
> postgreSQL. Since the isnull() function is no longer supported in 9.6
> version. I have tried every trick in the hat to get the desired results.
> Still 'RPG INV' doesn't show only the other two then options show up.
>
> (case
> when
> ((`s`.`Funding_Date` = '')
> and (isnull(`s`.`Actual_Close_Date`)
> or (`s`.`Actual_Close_Date` = '')))
> then
> 'RPG_INV'
> when
> ((isnull(`s`.`Funding_Date`)
> or (`s`.`Funding_Date` <> ''))
> and ((`s`.`Actual_Close_Date` = '')
> or isnull(`s`.`Actual_Close_Date`)))
> then
> 'Builder_Inventory'
> else 'Owner_Inventory'
> end) AS `Lot_Status`
>
>
​If you include something like the following people are going to be more
willing to provide help and better able to provide good help.

WITH dt (funding_date, actual_date) AS (
VALUES (null, null), ('X', 'X'),
(null, ''), (null, 'X'),
('', null), ('X', null)
)
SELECT funding_date, actual_date,
CASE WHEN funding_date IS NULL
AND actual_date IS NULL
THEN 'Both Null'
ELSE 'write more WHEN statements...'
END
FROM dt
​;

That's a self-contained example and it does wonders for problem solving.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2016-10-03 22:15:58 Make psql print number values right-aligned with locale group separator?
Previous Message otar shavadze 2016-10-03 20:16:36 Re: [GENERAL] Understanding “max_wal_size” and “min_wal_size” parameters default values from postgresql.conf file