Re: create view problem - Mailing list pgsql-sql

From Christopher Kings-Lynne
Subject Re: create view problem
Date
Msg-id GNELIHDDFBOCMGBFGEFOKEOKCBAA.chriskl@familyhealth.com.au
Whole thread Raw
In response to create view problem  (Mathieu Arnold <mat@mat.cc>)
Responses Upgrading PostgreSQL to 7.1.3  (Gordon Clarke <gordonc@adf-serials.com>)
List 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 VIEWtrafic_day
ASSELECT stats.ip, date(stats."time") AS date, count(*) AS nb, sum(stats.packet) AS packet, sum(stats.traffic) AS
trafficFROMstatsWHERE time::date < CURRENT_DATEGROUP 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...




pgsql-sql by date:

Previous
From: Mathieu Arnold
Date:
Subject: create view problem
Next
From: Oliver Elphick
Date:
Subject: Re: psql and password