X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7FC314763B2 for ; Sat, 22 Mar 2003 11:17:15 -0500 (EST) Received: from megazone.bigpanda.com (megazone.bigpanda.com [63.150.15.178]) by postgresql.org (Postfix) with ESMTP id 433C7474E4F for ; Sat, 22 Mar 2003 11:17:15 -0500 (EST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 13071D619; Sat, 22 Mar 2003 08:17:20 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 088255C02; Sat, 22 Mar 2003 08:17:20 -0800 (PST) Date: Sat, 22 Mar 2003 08:17:19 -0800 (PST) From: Stephan Szabo To: Rajesh Kumar Mallah Cc: Subject: Re: SQL help for efficient time handling.. In-Reply-To: <200303221332.33121.mallah@trade-india.com> Message-ID: <20030322081350.R1246-100000@megazone23.bigpanda.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Status: No, hits=-9.8 required=5.0 tests=EMAIL_ATTRIBUTION,IN_REP_TO autolearn=ham version=2.50-cvs X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50-cvs (1.172-2003-02-14-exp) X-Archive-Number: 200303/527 X-Sequence-Number: 12566 On Sat, 22 Mar 2003, Rajesh Kumar Mallah wrote: > To get current_time_id i use a query like > SELECT time_id from time_dimension where sql_time=date_trunc('minute' , cast(now() as time without time zone) ); > > it works but uses seq_scan > Seq Scan on time_dimension (cost=0.00..35.00 rows=5 width=4) (actual time=4.75..8.16 rows=1 loops=1) > Filter: ((sql_time)::interval = date_trunc('minute'::text, ((now())::time without time zone)::interval)) > Total runtime: 8.20 msec How about something like: select time_id from time_dimension where sql_time= cast(date_trunc('minute', now()) as time);