Null Conversion

Started by Mike Withersover 24 years ago5 messagesgeneral
Jump to latest
#1Mike Withers
M.withers@uws.edu.au

Can anyone tell me how I might convert a null attribute value into a zero
attribute value such that it can be multiplied in a query.

In Oracle I could do:

sal*12*NVL(COMM, 0) AS "Annual Income"

where COMM is an attribute (a salesman commission, in an employes table)
which has null values. This allows null commissions for non salesmen to
give a zero calculated value. The NVL converts a null into zero.

Thanks in anticipation
Mike Withers
University of Western Sydney
Australia

#2Jason Turner
jasont@indigoindustrial.co.nz
In reply to: Mike Withers (#1)
Re: Null Conversion

Can anyone tell me how I might convert a null attribute value into a zero
attribute value such that it can be multiplied in a query.

In Oracle I could do:

sal*12*NVL(COMM, 0) AS "Annual Income"

sal * 12 * CAST(COMM AS float8) AS "Annual Income"

Cheers

Jason
--
Indigo Industrial Controls Ltd.
64-21-343-545
jasont@indigoindustrial.co.nz

#3Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Mike Withers (#1)
Re: Null Conversion

On Wed, 15 Aug 2001, Mike Withers wrote:

Can anyone tell me how I might convert a null attribute value into a zero
attribute value such that it can be multiplied in a query.

In Oracle I could do:

sal*12*NVL(COMM, 0) AS "Annual Income"

where COMM is an attribute (a salesman commission, in an employes table)
which has null values. This allows null commissions for non salesmen to
give a zero calculated value. The NVL converts a null into zero.

Try coalesce(COMM, 0)

#4Mike Withers
M.withers@uws.edu.au
In reply to: Stephan Szabo (#3)
Re: Null Conversion

At 06:30 PM 8/14/01 -0700, you wrote:

On Wed, 15 Aug 2001, Mike Withers wrote:

Can anyone tell me how I might convert a null attribute value into a zero
attribute value such that it can be multiplied in a query.

In Oracle I could do:

sal*12*NVL(COMM, 0) AS "Annual Income"

where COMM is an attribute (a salesman commission, in an employes table)
which has null values. This allows null commissions for non salesmen to
give a zero calculated value. The NVL converts a null into zero.

Try coalesce(COMM, 0)

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Thanks, this works. Tried the other suggestion:

sal * 12 * CAST(COMM AS float8) AS "Annual Income"

which unfortunately didn't work.

#5Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Mike Withers (#4)
Re: Null Conversion

On Wed, 15 Aug 2001, Mike Withers wrote:

At 06:30 PM 8/14/01 -0700, you wrote:

On Wed, 15 Aug 2001, Mike Withers wrote:

Can anyone tell me how I might convert a null attribute value into a zero
attribute value such that it can be multiplied in a query.

In Oracle I could do:

sal*12*NVL(COMM, 0) AS "Annual Income"

where COMM is an attribute (a salesman commission, in an employes table)
which has null values. This allows null commissions for non salesmen to
give a zero calculated value. The NVL converts a null into zero.

Try coalesce(COMM, 0)

Thanks, this works. Tried the other suggestion:

sal * 12 * CAST(COMM AS float8) AS "Annual Income"

which unfortunately didn't work.

Yeah, that'll still give you a null out. I guess oracle must have
done nvl before the standards group decided on coalesce for the name
of that.