From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: Can i customize null-padding for outer joins?
Date: Thu, 1 Oct 2009 08:40:21 +0200
Message-ID: <20091001064021.GA25444@a-kretschmer.de> (raw)
In-Reply-To: <6caee9520909302319w638c4feara4ead3402e5e00c0@mail.gmail.com>
References: <6caee9520909302319w638c4feara4ead3402e5e00c0@mail.gmail.com>
In response to Shruthi A :
> Hello,
>
> I have a query where I full-outer-join 2 tables, and all the columns other than
> the join column are numerical columns. For my further calculations i need to
> pad the unmatched tuples with 0 (zero) instead of NULL so that I can perform
> meaningful mathematical calculations on them. Is this currently possible?
You can use COALESCE() in your numerical calculation, for instance:
test=*# create table foo (n numeric);
CREATE TABLE
test=*# insert into foo values (1),(NULL),(NULL);
INSERT 0 3
test=*# select avg(n) from foo;
avg
------------------------
1.00000000000000000000
(1 row)
test=*# select avg(coalesce(n,0)) from foo;
avg
------------------------
0.33333333333333333333
(1 row)
Or use coalesce in your join-statement:
select coalesce(column,0) ...
Regards, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: andreas.kretschmer@schollglas.com
Subject: Re: Can i customize null-padding for outer joins?
In-Reply-To: <20091001064021.GA25444@a-kretschmer.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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