Re: [GENERAL] COALESCE() or NVL()

From: rmcm(at)compsoft(dot)com(dot)au
To: "Jose' Soares Da Silva" <sferac(at)bo(dot)nettuno(dot)it>
Cc: pgsql-general(at)hub(dot)org
Subject: Re: [GENERAL] COALESCE() or NVL()
Date: 1998-06-13 03:37:03
Message-ID: 13697.62431.496047.616471@truffaut.int.compsoft.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

I got sum(money attribute) to return 0.00 instead of NULL when there
are zero tuples in class, by redefining the sum() aggregate to set
initcond1 to 0.00. Perhaps you do something similar with your AVL().

-- Replace existing sum(money) to return $0.00
-- for zero instances

drop aggregate sum money;
create aggregate sum (sfunc1 = cash_pl, -- sum
basetype = money,
stype1 = money,
initcond1 = '0.00');

Jose' Soares Da Silva writes:
> Hi all,
>
> I'm looking for a function like COALESCE() or the Oracle NVL(),
> to returns a ZERO value instead of a NULL value.
> To have the result: NULL+1 = 1 instead of NULL+1 = NULL
> Have PostgreSQL something like this ?
> I tried to write it on C but I can't realize the beavior of NULLs,
> I can't get that my program returns a zero instead of a null.
> I'm not a C programmer, could somebody help me ?
>
> SELECT * FROM emp;
> name |salary|age|dept
> -----------+------+---+-----
> Sam | 1200| 16|toy
> Claire | 5000| 32|shoe
> Bill | 4200| 36|shoe
> Ginger | 4800| 30|candy
> NULL VALUES| | |
> (5 rows)
>
> SELECT name,NVL(salary)+100 AS dream FROM emp;
> name |dream
> -----------+-----
> Sam | 1300
> Claire | 5100
> Bill | 4300
> Ginger | 4900
> NULL VALUES| <--- I expected 100 here.
> (5 rows)
> Thanks, Jose'
> | |
> ~~~~~~~~~~~~~~~~~~~~~~~~ | | ~~~~~~~~~~~~~~~~~~~~~~~~
> Progetto HYGEA ---- ---- www.sferacarta.com
> Sfera Carta Software ---- ---- sferac(at)bo(dot)nettuno(dot)it
> Via Bazzanese, 69 | | Fax. ++39 51 6131537
> Casalecchio R.(BO) Italy | | Tel. ++39 51 591054
>

--
------------------------------------------------------------
Rex McMaster rmcm(at)compsoft(dot)com(dot)au
rex(at)mcmaster(dot)wattle(dot)id(dot)au
PGP Public key: http://www.compsoft.com.au/~rmcm/pgp-pk

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message info 1998-06-14 16:34:37 Autoresponder-Family Tree Chart
Previous Message David Welton 1998-06-12 22:30:03 Postgresql 6.3.1 on Irix 6.2

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1998-06-13 04:26:51 Re: [QUESTIONS] How is PostgreSQL doing?
Previous Message Park, Chul-Su 1998-06-13 02:18:30 [QUESTIONS] builtin lo_unlink(int4)? why int4 not oid?