pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
MAX(column1),MAX(column2),...
4+ messages / 3 participants
[nested] [flat]

* MAX(column1),MAX(column2),...
@ 2002-04-15 18:38  Bjarte Aagnes <bjartea@student.sv.uio.no>
  0 siblings, 1 reply; 4+ messages in thread

From: Bjarte Aagnes @ 2002-04-15 18:38 UTC (permalink / raw)
  To: pgsql-sql

Hi,

How do I list all column names and maximum values for each column in a table.
I can list the column names, but can't see how to get the maximum of each
column without typing max(name) for every column.

Regards
Bjarte Aagnes




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: MAX(column1),MAX(column2),...
@ 2002-04-15 19:34  Josh Berkus <josh@agliodbs.com>
  parent: Bjarte Aagnes <bjartea@student.sv.uio.no>
  0 siblings, 1 reply; 4+ messages in thread

From: Josh Berkus @ 2002-04-15 19:34 UTC (permalink / raw)
  To: Bjarte Aagnes <bjartea@student.sv.uio.no>; pgsql-sql

Bjarte,

> How do I list all column names and maximum values for each column in
> a table.
> I can list the column names, but can't see how to get the maximum of
> each
> column without typing max(name) for every column.

That is exactly what you have to do.   I do not understand the problem.
 If you are looking for some way to save yourself typing the column
names, it doesn't exist.

-Josh Berkus



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: MAX(column1),MAX(column2),...
@ 2002-04-15 20:17  Travis Hoyt <thoyt@npc.net>
  parent: Josh Berkus <josh@agliodbs.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Travis Hoyt @ 2002-04-15 20:17 UTC (permalink / raw)
  To: Josh Berkus <josh@agliodbs.com>; Bjarte Aagnes <bjartea@student.sv.uio.no>; pgsql-sql

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().

Travis

-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org]On Behalf Of Josh Berkus
Sent: Monday, April 15, 2002 3:34 PM
To: Bjarte Aagnes; pgsql-sql@postgresql.org
Subject: Re: [SQL] MAX(column1),MAX(column2),...


Bjarte,

> How do I list all column names and maximum values for each column in
> a table.
> I can list the column names, but can't see how to get the maximum of
> each
> column without typing max(name) for every column.

That is exactly what you have to do.   I do not understand the problem.
 If you are looking for some way to save yourself typing the column
names, it doesn't exist.

-Josh Berkus

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Attachments:

  smime.p7s (application/x-pkcs7-signature, 3.0K) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: [SQL] MAX(column1),MAX(column2),...
@ 2002-04-19 13:00  Bjarte Aagnes <bjartea@student.sv.uio.no>
  parent: Travis Hoyt <thoyt@npc.net>
  0 siblings, 0 replies; 4+ messages in thread

From: Bjarte Aagnes @ 2002-04-19 13:00 UTC (permalink / raw)
  To: pgsql-novice@postgresql.org


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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2002-04-19 13:00 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-04-15 18:38 MAX(column1),MAX(column2),... Bjarte Aagnes <bjartea@student.sv.uio.no>
2002-04-15 19:34 ` Josh Berkus <josh@agliodbs.com>
2002-04-15 20:17   ` Travis Hoyt <thoyt@npc.net>
2002-04-19 13:00     ` Bjarte Aagnes <bjartea@student.sv.uio.no>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox