pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: record fields as columns in reports
Date: Fri, 29 Jun 2007 06:57:37 +0200
Message-ID: <20070629045737.GA17977@a-kretschmer.de> (raw)
In-Reply-To: <20070628144615.GQ72343@spoetnik.xs4all.nl>
References: <20070628144615.GQ72343@spoetnik.xs4all.nl>

am  Thu, dem 28.06.2007, um 16:46:15 +0200 mailte Reinoud van Leeuwen folgendes:
> Hi everybody,
> 
> I have a script that runs every night and produces a list of a few error 
> conditions and the number.
> 
> My manager would like it in a form where he can produce some charts in a 
> spreadsheet (that's probably why he's a manager ";-).
> 
> So the table I store the errormessages in has a format like this:
> 
> CREATE TABLE repport_history
> (
>   rundate date,
>   errordescription character varying(255),
>   number bigint
> ) 
> 
> 
> And I would like an output with something like:
> 
>           06/22     06/23    06/24    06/25
> ERROR1     10         10       9         8
> ERROR2    250        300     220       200
> ERROR3      4          2       0         0
> 
> 
> (probably in csv or something like that but that is the easy part ";-)
> 
> The problems are:
> - how to create a dynamic result type? (is that possible in a stored 
> procedure?)
> - how to make sure that missing records are reported as 0
>   (some errors might not have entries on some dates)

You can do it with conditionals. Circa:

select errordescription, sum (case when rundate = '2007-06-22'::date
then number else 0 end) as "06/22", sum(case when rundate =
'2007-06-23'::date then number else 0 end) as "06/23" ... group by
errordescription order by errordescription;

and you can use a VIEW and change the fix conditions to expressions with
current_date.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net



view thread (4+ messages)

Message-ID: <20070629045737.GA17977@a-kretschmer.de>
Permalink:  ../20070629045737.GA17977@a-kretschmer.de/
Also on:    postgresql.org/message-id/20070629045737.GA17977@a-kretschmer.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andreas.kretschmer@schollglas.com
  Subject: Re: record fields as columns in reports
  In-Reply-To: <20070629045737.GA17977@a-kretschmer.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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