Re: [SQL] MAX(column1),MAX(column2),... - Mailing list pgsql-novice

From Bjarte Aagnes
Subject Re: [SQL] MAX(column1),MAX(column2),...
Date
Msg-id Pine.SOL.4.33.0204191431010.7548-100000@ulrik.uio.no
Whole thread Raw
List pgsql-novice
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


pgsql-novice by date:

Previous
From: sophie yang
Date:
Subject: algebraic rewriting
Next
From: "Josh Berkus"
Date:
Subject: Re: algebraic rewriting