X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 81DF1D1B52A for ; Mon, 29 Sep 2003 13:57:18 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 86533-09 for ; Mon, 29 Sep 2003 10:56:51 -0300 (ADT) Received: from beamish.nsd.ca (beamish.nsd.ca [205.150.156.194]) by svr1.postgresql.org (Postfix) with ESMTP id 1CE90D1B535 for ; Mon, 29 Sep 2003 10:56:47 -0300 (ADT) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id JAA26234; Mon, 29 Sep 2003 09:56:40 -0400 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma026230; Mon, 29 Sep 03 09:56:18 -0400 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id JAA08170; Mon, 29 Sep 2003 09:42:37 -0400 Message-ID: <3F783BD8.48101D85@nsd.ca> Date: Mon, 29 Sep 2003 10:04:08 -0400 From: Jean-Luc Lachance X-Mailer: Mozilla 4.8 [en] (X11; U; Linux 2.4.18-24.7.x i686) X-Accept-Language: en MIME-Version: 1.0 To: Tom Lane Cc: Dan Langille , pgsql-sql@postgresql.org Subject: Re: References: <20030928151910.S78282@laptop.unixathome.org> <10801.1064778322@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/383 X-Sequence-Number: 15361 Wouldn't: insert into r select count(*) from users where date( lastlogin) > current_date - MaxDays * interval '' 1 day'' group by date( lastlogin); be more efficient? Tom Lane wrote: > > Dan Langille writes: > > WHERE lastlogin between current_date - interval \''' || > > quote_literal(i - 1) || '' days\' > > AND current_date - interval \''' || > > quote_literal(i) || '' days\'''; > > IIRC, quote_literal() puts single quotes around its result. So you have > too many quotes there. Given that you know i is an integer, you don't > really need quote_literal for it. Actually, you don't need EXECUTE > here at all. Why not just > > FOR i IN 1..MaxDays LOOP > SELECT count(*) > INTO r > FROM users > WHERE lastlogin between current_date - (i-1) * interval ''1 day'' > AND current_date - i * interval ''1 day''; > RETURN NEXT r; > END LOOP; > > regards, tom lane > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings