+ operator with a possible NULL operand - Mailing list pgsql-novice

From Michael Glaesemann
Subject + operator with a possible NULL operand
Date
Msg-id 84210D83-919A-11D7-BEFD-0005029FC1A7@myrealbox.com
Whole thread Raw
In response to Re: Advisable to move SQL from PHP to functions?  (Josh Berkus <josh@agliodbs.com>)
Responses Re: + operator with a possible NULL operand
List pgsql-novice
I'm getting my feet wet using PostgreSQL and have run in to a bit of a
snag with using the + operator.

I want to create a table that has a third column that is the sum of the
values of two other columns. In essence:

SELECT    a.qty AS aa,
        b.qty AS bb,
        a.qty + b.qty AS cc
    FROM ...

The FROM is a subquery that includes a number of full joins, so there
are occasions when a.qty or b.qty are NULL.

The select statement seems to work just fine, except that where a.qty
or b.qty are NULL, cc is also NULL. (I can see how this might not work,
PostgreSQL protesting, "Okay, you want me to add this and ... and ...
and what, exactly?" But maybe I've misconceived what the problem is.)

I've googled for "postgresql mathematical operator null argument",
taken a gander at the html help files included with the PostgreSQL
installation and through Practical PostgreSQL in the sections on
mathematical operators, but didn't find anything that mentions this.
I'm probably not looking in the right places.

If someone point me in the direction I should look, I'd really
appreciate it.

Thanks for your time!

Michael Glaesemann
grzm myrealbox com


pgsql-novice by date:

Previous
From: Nabil Sayegh
Date:
Subject: Re: Inserting data of two other tables [Now deleting ...]
Next
From: Tom Lane
Date:
Subject: Re: + operator with a possible NULL operand