'GROUP BY' problem - Mailing list pgsql-general

From Mariusz Czułada
Subject 'GROUP BY' problem
Date
Msg-id 200301300923.50894.manieq@idea.net.pl
Whole thread Raw
List pgsql-general
Hi all,

I have a table:

CREATE TABLE tmp_server_perf_sum (
    ts timestamp without time zone,
    lock_count double precision,
    cpu_busy_pct double precision,
    transactions_rate double precision,
    deadlock_count double precision
);

/* data from Sybase Historical Server */

I can:

SELECT
    date_trunc('hour',ts),
    min(cpu_busy_pct),
    avg(cpu_busy_pct),
    max(cpu_busy_pct)
FROM
    tmp_server_perf_sum
GROUP BY
    date_trunc('hour',ts);

and it works great. But 1h interval is to wide for me. On the over hand 1
minute is less than my samples in table. I'd like to group results for every
15 minues. I'd love to do it this way:

SELECT
    date_trunc('15 minutes',ts),
    min(cpu_busy_pct),
    avg(cpu_busy_pct),
    max(cpu_busy_pct)
FROM
    tmp_server_perf_sum
GROUP BY
    date_trunc('15 minutes',ts);

but unfortunately it is not working (I use 7.2.2, but IMHO it is not
important).

1. Can sb. help me with this query? How to make such groupping?

2. Do you think is it possible/needed to extend 'date_trunc' function to
support such options?

TIA

Mariusz Czulada


pgsql-general by date:

Previous
From: Holger Klawitter
Date:
Subject: donations?
Next
From: Holger Klawitter
Date:
Subject: Re: Firewalls and Postgres