Skip site navigation (1) Skip section navigation (2)

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

From: Bjarte Aagnes <bjartea(at)student(dot)sv(dot)uio(dot)no>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: [SQL] MAX(column1),MAX(column2),...
Date: 2002-04-19 13:00:09
Message-ID: Pine.SOL.4.33.0204191431010.7548-100000@ulrik.uio.no (view raw or flat)
Thread:
Lists: pgsql-novicepgsql-sql
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


In response to

pgsql-novice by date

Next:From: Josh BerkusDate: 2002-04-19 16:07:38
Subject: Re: algebraic rewriting
Previous:From: sophie yangDate: 2002-04-19 06:42:23
Subject: algebraic rewriting

pgsql-sql by date

Next:From: St├ęphane DEWITTEDate: 2002-04-19 14:39:43
Subject: How to log outputs from pl/pgsql into a file ?
Previous:From: Christoph HallerDate: 2002-04-19 11:46:48
Subject: Re: count different values in column

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group