Thread: Re: [SQL] MAX(column1),MAX(column2),...

Re: [SQL] MAX(column1),MAX(column2),...

From
Bjarte Aagnes
Date:
On Mon, 15 Apr 2002, Travis Hoyt wrote:

> You could write a plpgsql function to select all the column names from the
> one of the system tables and do max($myvar) for each of the column names
> returned.
>
> select attname from pg_stats where tablename = 'yourtablename';
>
> Will get you the list of columns.  Just write a loop the loop through each
> one and do max().

Thanks,

When variable 'dsvarname' with value 'WEIGHT' is argument to MAX() it
returns WEIGHT and not what I expected the maximum of the WEIGHT column:

     FOR row_data IN SELECT ...

     LOOP
       dsvarname = CAST(row_data.variabel AS varchar);
     END LOOP;

     CREATE TABLE wbtmp99 AS SELECT
     dsvarname AS variabel,
     MIN(\"WEIGHT\"),
     MAX(dsvarname)
     FROM \"ANIMALS\";


 variabel | min  |  max
----------+------+--------
 WEIGHT   | 4.23 | WEIGHT


Regards,
Bjarte Aagnes