Dalla versione 8.4 di PostgreSQL è possibile utilizzare le Window Function.
(http://www.postgresql.org/docs/8.4/static/functions-window.html)
Queste "windowing aggregates" sono molto utili in operazioni complesse di datawarehousing e reporting dove le performance sono fattore determinante.
Un piccolo esempio:
SELECT
date_taken,
row_number() OVER(PARTITION BY date_taken::date)
FROM (
SELECT TIMESTAMP 'epoch' + f.a * INTERVAL '1 second' AS date_taken
FROM generate_series(EXTRACT(EPOCH
FROM '2012-06-25' ::timestamp) ::bigint,
EXTRACT(EPOCH
FROM current_timestamp::timestamp) ::bigint, 300
)
AS f(a)
ORDER BY date_taken ASC
) t;
Nessun commento:
Posta un commento