X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 572BED1D387 for ; Thu, 22 Apr 2004 17:10:06 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 08645-04 for ; Thu, 22 Apr 2004 17:10:01 -0300 (ADT) Received: from smtp0.libero.it (smtp0.libero.it [193.70.192.33]) by svr1.postgresql.org (Postfix) with ESMTP id 96C01D1D1D5 for ; Thu, 22 Apr 2004 17:09:58 -0300 (ADT) Received: from noquarter.fepede.org (151.42.84.221) by smtp0.libero.it (7.0.027-DD01) id 404F12EF00AD77F6; Thu, 22 Apr 2004 22:09:58 +0200 Received: by noquarter.fepede.org (Postfix, from userid 1000) id 6AB802781C; Thu, 22 Apr 2004 22:09:54 +0200 (CEST) Date: Thu, 22 Apr 2004 22:09:54 +0200 From: Federico Pedemonte To: pgsql-general@postgresql.org Subject: Re: staggered query? Message-ID: <20040422200954.GF1044@noquarter.fepede.org> References: <002901c4274b$cb7ace30$643b1cac@Titanium> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <002901c4274b$cb7ace30$643b1cac@Titanium> User-Agent: Mutt/1.5.5.1+cvs20040105i X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=2.5 tagged_above=0.0 required=5.0 tests=RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_NJABL, RCVD_IN_SORBS X-Spam-Level: ** X-Archive-Number: 200404/867 X-Sequence-Number: 60109 On Wed, Apr 21, 2004 at 10:53:16AM +0800, Vincent Ladlad wrote: > > the table contains hundreds of thousands of records. > i need to get all the entries/records at every 10 seconds > interval. example, given a table: > > hh/mm/ss | data > --------------- > 00:00:00 1 > 00:00:01 2 > 00:00:02 3 > 00:00:03 4 > 00:00:04 5 > 00:00:05 6 > 00:00:06 7 > 00:00:07 8 > .. > .. > > my query should return: > 00:00:10 > 00:00:20 > 00:00:30 > (etc) If I understood your problem, the only solution i found was write a simple plpgsql function (read at the end of the mail). Don't know if it is the best solution but it works ! Ciao, Federico. ------------------------------------------------------------------------ Usage : select * from timetable ('23/06/1974 18:15', '23/06/1974 20:30', '00:10'); timetable --------------------- 1974-06-23 18:15:00 1974-06-23 18:25:00 1974-06-23 18:35:00 1974-06-23 18:45:00 1974-06-23 18:55:00 ... CREATE OR REPLACE FUNCTION timetable(timestamp, timestamp, interval) RETURNS SETOF timestamp AS ' DECLARE inizio alias for $1; fine alias for $2 ; inter alias for $3; tt timestamp; BEGIN tt := inizio; while tt <= fine loop return next tt; tt:=tt+inter; end loop; RETURN ; END; ' LANGUAGE plpgsql IMMUTABLE;