| From: | merlyn(at)stonehenge(dot)com (Randal L(dot) Schwartz) |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: timestamped archive data index searches |
| Date: | 2002-07-20 19:51:00 |
| Message-ID: | 86d6ti6uvv.fsf@blue.stonehenge.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
>>>>> "Tom" == Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:
Tom> "Stephen Birch" <sgbirch(at)hotmail(dot)com> writes:
>> I also tried the following, which explain said is also using a sequence scan
>> :-(
>> SELECT sum(vol) FROM det
>> WHERE tstamp > (current_timestamp - '5 seconds'::interval);
Tom> This doesn't work (in 7.2 and before) because the planner doesn't think
Tom> current_timestamp is a constant. You can get around that with a custom
Tom> function that hides the current_timestamp computation and is marked
Tom> isCachable --- this is a cheat but works well enough in interactive
Tom> queries. (It'd not work inside plpgsql unfortunately.) See past
Tom> archived discussions --- searching for isCachable should turn up
Tom> examples.
I've found this to work:
SELECT sum(vol) FROM det
WHERE tstamp > (select current_timestamp - '5 seconds'::interval);
I don't know where I got that trick from, but it works fine.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn(at)stonehenge(dot)com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bruno Wolff III | 2002-07-20 19:51:35 | Why can't comment strings be expressions? |
| Previous Message | Stephen Birch | 2002-07-20 19:29:08 | Re: timestamped archive data index searches |