pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
timestamp/now in views
3+ messages / 3 participants
[nested] [flat]

* timestamp/now in views
@ 1999-12-08 23:18 Graeme Merrall <gmerrall@email.com>
  1999-12-09 01:15 ` Re: [SQL] timestamp/now in views Tom Lane <tgl@sss.pgh.pa.us>
  1999-12-09 15:18 ` Re: [SQL] timestamp/now in views Jan Wieck <wieck@debis.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Graeme Merrall @ 1999-12-08 23:18 UTC (permalink / raw)
  To: pgsql-sql

Sorry for being an idiot but I saw something similar to this in the docs but
haven't been able to find it since.
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.
I hacked around with various combos of quote marks and tried now() and so
on, but to no avail.

Can someone enlighten me?

Cheers,
 Graeme




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [SQL] timestamp/now in views
  1999-12-08 23:18 timestamp/now in views Graeme Merrall <gmerrall@email.com>
@ 1999-12-09 01:15 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 1999-12-09 01:15 UTC (permalink / raw)
  To: Graeme Merrall <gmerrall@email.com>; +Cc: pgsql-sql

"Graeme Merrall" <gmerrall@email.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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: [SQL] timestamp/now in views
  1999-12-08 23:18 timestamp/now in views Graeme Merrall <gmerrall@email.com>
@ 1999-12-09 15:18 ` Jan Wieck <wieck@debis.com>
  1 sibling, 0 replies; 3+ messages in thread

From: wieck@debis.com @ 1999-12-09 15:18 UTC (permalink / raw)
  To: gmerrall@email.com; +Cc: pgsql-sql

> 
> Sorry for being an idiot but I saw something similar to this in the docs but
> haven't been able to find it since.
> 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');

    ... WHERE audit_datetime > 
				timestamp('now'::text) + '@24hours'::interval

	That one should work.


Jan

-- 

#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me.                                  #
#========================================= wieck@debis.com (Jan Wieck) #




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~1999-12-09 15:18 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-12-08 23:18 timestamp/now in views Graeme Merrall <gmerrall@email.com>
1999-12-09 01:15 ` Tom Lane <tgl@sss.pgh.pa.us>
1999-12-09 15:18 ` Jan Wieck <wieck@debis.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox