pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedchange null to 0 in SQL script
6+ messages / 5 participants
[nested] [flat]
* change null to 0 in SQL script
@ 2002-01-03 05:00 Karl Raven <lcaasia@pd.jaring.my>
0 siblings, 4 replies; 6+ messages in thread
From: Karl Raven @ 2002-01-03 05:00 UTC (permalink / raw)
To: pgsql-sql
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
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: change null to 0 in SQL script
@ 2002-01-03 14:59 Markus Bertheau <twanger@bluetwanger.de>
parent: Karl Raven <lcaasia@pd.jaring.my>
3 siblings, 0 replies; 6+ messages in thread
From: Markus Bertheau @ 2002-01-03 14:59 UTC (permalink / raw)
To: Karl Raven <lcaasia@pd.jaring.my>; +Cc: pgsql-sql
On Thu, 2002-01-03 at 06:00, Karl Raven wrote:
>
> 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?
What did you try?
Markus Bertheau
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: change null to 0 in SQL script
@ 2002-01-03 15:45 Tibor Laszlo <ltibor@mail.tiszanet.hu>
parent: Karl Raven <lcaasia@pd.jaring.my>
3 siblings, 0 replies; 6+ messages in thread
From: Tibor Laszlo @ 2002-01-03 15:45 UTC (permalink / raw)
To: Karl Raven <lcaasia@pd.jaring.my>; pgsql-sql
> I like to change a null value of a query to 0
The coalesce(something, 0) returns 0 if something is null, else returns
something.
Tibor Laszlo
ltibor@mail.tiszanet.hu
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: change null to 0 in SQL script
@ 2002-01-03 16:20 Jason Earl <jason.earl@simplot.com>
parent: Karl Raven <lcaasia@pd.jaring.my>
3 siblings, 0 replies; 6+ messages in thread
From: Jason Earl @ 2002-01-03 16:20 UTC (permalink / raw)
To: Karl Raven <lcaasia@pd.jaring.my>; +Cc: 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@pd.jaring.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@postgresql.org
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: change null to 0 in SQL script
@ 2002-01-04 19:52 ThomasR <trx@wtal.de>
parent: Karl Raven <lcaasia@pd.jaring.my>
3 siblings, 1 reply; 6+ messages in thread
From: ThomasR @ 2002-01-04 19:52 UTC (permalink / raw)
To: pgsql-sql
Karl Raven wrote:
> 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
>
I think the following should work:
select coalesce( my_attrib, 0 ) from my_tab
Thomas
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: change null to 0 in SQL script
@ 2002-01-05 20:54 Karl Raven <lcaasia@pd.jaring.my>
parent: ThomasR <trx@wtal.de>
0 siblings, 0 replies; 6+ messages in thread
From: Karl Raven @ 2002-01-05 20:54 UTC (permalink / raw)
To: pgsql-sql
thanks
will try it..
"ThomasR" <trx@wtal.de> wrote in message news:3C360816.1080103@wtal.de...
> Karl Raven wrote:
>
> > 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
> >
>
> I think the following should work:
>
> select coalesce( my_attrib, 0 ) from my_tab
>
> Thomas
>
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2002-01-05 20:54 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-01-03 05:00 change null to 0 in SQL script Karl Raven <lcaasia@pd.jaring.my>
2002-01-03 14:59 ` Markus Bertheau <twanger@bluetwanger.de>
2002-01-03 15:45 ` Tibor Laszlo <ltibor@mail.tiszanet.hu>
2002-01-03 16:20 ` Jason Earl <jason.earl@simplot.com>
2002-01-04 19:52 ` ThomasR <trx@wtal.de>
2002-01-05 20:54 ` Karl Raven <lcaasia@pd.jaring.my>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox