From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Graeme Merrall" <gmerrall(at)email(dot)com> |
Cc: | pgsql-sql(at)postgreSQL(dot)org |
Subject: | Re: [SQL] timestamp/now in views |
Date: | 1999-12-09 01:15:56 |
Message-ID: | 29104.944702156@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
"Graeme Merrall" <gmerrall(at)email(dot)com> writes:
> I tried creating a view using the following syntax
> CREATE VIEW prev_day AS SELECT * FROM audit WHERE audit_datetime >
> (current_timestamp - interval'24 hours');
> Now as some of you will pick up, this creates a view with the current
> timestamp set to the creation time of the view, not the actual time the view
> was executed.
Yes --- this is fixed in current sources, but that doesn't help you on
release versions :-(
> I hacked around with various combos of quote marks and tried now() and so
> on, but to no avail.
Just substituting now() for current_timestamp seemed to work fine for
me in 6.5.3:
play=> CREATE VIEW prev_day AS SELECT * FROM audit WHERE audit_datetime >
play-> (now() - interval'24 hours');
CREATE
play=> \d prev_day
View = prev_day
Query = SELECT "audit"."f1", "audit"."audit_datetime" FROM "audit" WHERE ("datetime"("audit"."audit_datetime") > ("datetime"("now"()) - '@ 1 day'::"timespan"));
As you can see, the stored form of the query still has now() rather than
a constant datetime value...
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | De Moudt Walter | 1999-12-09 02:11:59 | Re: [SQL] subquery, except and view |
Previous Message | Peter Eisentraut | 1999-12-09 00:18:44 | Re: [SQL] turning a table by 90 degrees |