From: | "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au> |
---|---|
To: | "Mathieu Arnold" <mat(at)mat(dot)cc>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: create view problem |
Date: | 2002-03-28 07:04:41 |
Message-ID: | GNELIHDDFBOCMGBFGEFOKEOKCBAA.chriskl@familyhealth.com.au |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
> I wanted to add some test on time, so I did a
> CREATE VIEW
> trafic_day
> AS
> SELECT
> stats.ip,
> date(stats."time") AS date,
> count(*) AS nb,
> sum(stats.packet) AS packet,
> sum(stats.traffic) AS traffic
> FROM
> stats
> WHERE
> time::date < 'now'::date
> GROUP BY
> stats.ip,
> date(stats."time")
> ORDER BY
> sum(stats.traffic) DESC;
'Now' is evaluated at creation time. A special hack exists if it is set as
a default column value to evaluate it at insert time. Change it to this:
CREATE VIEW
trafic_day
AS
SELECT
stats.ip,
date(stats."time") AS date,
count(*) AS nb,
sum(stats.packet) AS packet,
sum(stats.traffic) AS traffic
FROM
stats
WHERE
time::date < CURRENT_DATE
GROUP BY
stats.ip,
date(stats."time")
ORDER BY
sum(stats.traffic) DESC;
You don't even need the 'time::date' bit - just use 'time'.
Cheers,
Chris
ps. You spelled 'traffic' as 'trafic' above...
From | Date | Subject | |
---|---|---|---|
Next Message | Oliver Elphick | 2002-03-28 07:11:22 | Re: psql and password |
Previous Message | Mathieu Arnold | 2002-03-28 06:58:34 | create view problem |