+ operator with a possible NULL operand

Поиск
Список
Период
Сортировка
От Michael Glaesemann
Тема + operator with a possible NULL operand
Дата
Msg-id 84210D83-919A-11D7-BEFD-0005029FC1A7@myrealbox.com
обсуждение исходный текст
Ответ на Re: Advisable to move SQL from PHP to functions?  (Josh Berkus <josh@agliodbs.com>)
Ответы Re: + operator with a possible NULL operand  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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 по дате отправления:

Предыдущее
От: Nabil Sayegh
Дата:
Сообщение: Re: Inserting data of two other tables [Now deleting ...]
Следующее
От: Tom Lane
Дата:
Сообщение: Re: + operator with a possible NULL operand