Re: change null to 0 in SQL script

From: Jason Earl <jason(dot)earl(at)simplot(dot)com>
To: "Karl Raven" <lcaasia(at)pd(dot)jaring(dot)my>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: change null to 0 in SQL script
Date: 2002-01-03 16:20:17
Message-ID: 87itaj5rum.fsf@npa01zz001.simplot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


I believe that you need the coalesce function. Here's the excerpt
from the manual:

COALESCE

COALESCE(value[, ...])

The COALESCE function returns the first of its arguments that
is not NULL. This is often useful to substitute a default
value for NULL values when data is retrieved for display, for
example:

SELECT COALESCE(description, short_description, '(none)') ...

Just write your query so that it looks something like this:

SELECT coalesce(value_that_may_be_null, 0) FROM your_table;

Jason

"Karl Raven" <lcaasia(at)pd(dot)jaring(dot)my> writes:

> I like to change a null value of a query to 0 in the SQL script. I
> know how to do it in MS-SQL server and MS-Access but those commands
> does not work in pg-sql.
>
> Anyone has any ideas?
>
> Thanks
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2002-01-03 17:04:38 Re: Conditional test
Previous Message Tibor Laszlo 2002-01-03 15:45:38 Re: change null to 0 in SQL script