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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-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

Browse pgsql-novice by date

  From Date Subject
Next Message Josh Berkus 2002-04-19 16:07:38 Re: algebraic rewriting
Previous Message sophie yang 2002-04-19 06:42:23 algebraic rewriting

Browse pgsql-sql by date

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