Re: Alias "all fields"? - Mailing list pgsql-general

From Tom Lane
Subject Re: Alias "all fields"?
Date
Msg-id 22556.1189089563@sss.pgh.pa.us
Whole thread Raw
In response to Alias "all fields"?  (Stefan Schwarzer <stefan.schwarzer@grid.unep.ch>)
List pgsql-general
Stefan Schwarzer <stefan.schwarzer@grid.unep.ch> writes:
> Instead of this:
>         SELECT * FROM gdp WHERE y1970 NOT NULL AND y1971 NOT NULL
> AND .... y2005 NOT NULL
> I would like to have this:
>        SELECT * FROM gdp WHERE all-fields NOT NULL

This idea seems rather pointless for any operation other than
null-testing, since nothing else would apply uniformly to all data
types.  For null-testing you can use row null tests:

regression=# select * from int8_tbl i;
        q1        |        q2
------------------+-------------------
              123 |               456
              123 |  4567890123456789
 4567890123456789 |               123
 4567890123456789 |  4567890123456789
 4567890123456789 | -4567890123456789
               22 |
                  |
(7 rows)

regression=# select * from int8_tbl i where row(i.*) is not null;
        q1        |        q2
------------------+-------------------
              123 |               456
              123 |  4567890123456789
 4567890123456789 |               123
 4567890123456789 |  4567890123456789
 4567890123456789 | -4567890123456789
(5 rows)

regression=#

Note: this only works the way you want in 8.2 and up; earlier versions
thought that "row is not null" meant that *any* field is not null,
rather than *all*.

            regards, tom lane

pgsql-general by date:

Previous
From: Franz.Rasper@izb.de
Date:
Subject: Re: Alias "all fields"?
Next
From: Tino Wildenhain
Date:
Subject: Re: Alias "all fields"?