Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VRbBm-00012W-DF for pgsql-sql@arkaria.postgresql.org; Thu, 03 Oct 2013 05:11:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VRbBl-0000Tt-Of for pgsql-sql@arkaria.postgresql.org; Thu, 03 Oct 2013 05:11:01 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VRbBk-0000Tm-O5 for pgsql-sql@postgresql.org; Thu, 03 Oct 2013 05:11:00 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VRbBh-00026k-F6 for pgsql-sql@postgresql.org; Thu, 03 Oct 2013 05:10:59 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1VRbBg-0004nD-2R for pgsql-sql@postgresql.org; Wed, 02 Oct 2013 22:10:56 -0700 Date: Wed, 2 Oct 2013 22:10:56 -0700 (PDT) From: gmb To: pgsql-sql@postgresql.org Message-ID: <1380777056063-5773196.post@n5.nabble.com> In-Reply-To: <1380762368253-5773171.post@n5.nabble.com> References: <1380751468173-5773160.post@n5.nabble.com> <1380762368253-5773171.post@n5.nabble.com> Subject: Re: Help needed with Window function MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 3.5 (+++) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org David Johnston wrote > Basic idea: use ORDER BY in the window to auto-define a range-preceding > frame. Create an array of all dates (tags in the example) that match with > positive amounts. Negative amounts get their matching tag added to the > array as NULL. The provided function looks into the generated array and > returns the last (closest to the current row in the frame) non-null > date/tag in the array which ends up being the date/tag matching the last > positive amount in the frame. > > David J. Hi David, Thanks for your reply. This is an approach I also considered, but hoped for a solution without the expense (albeit small) of having to create a function. Just wanted to confirm that I'm not missing a simpler solution (my knowledge in terms of window functions is rather limited). Until something better comes along, I'll implement the solution as suggested here. Regards GMB -- View this message in context: http://postgresql.1045698.n5.nabble.com/Help-needed-with-Window-function-tp5773160p5773196.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql