Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bsJ09-0008TN-Bz for pgsql-sql@arkaria.postgresql.org; Fri, 07 Oct 2016 00:27:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bsJ08-0007Um-Mv for pgsql-sql@arkaria.postgresql.org; Fri, 07 Oct 2016 00:27:00 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bsJ08-0007Uf-5A for pgsql-sql@postgresql.org; Fri, 07 Oct 2016 00:27:00 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bsJ05-0001Gn-E3 for pgsql-sql@postgresql.org; Fri, 07 Oct 2016 00:26:58 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id A4B2820509; Thu, 6 Oct 2016 20:26:56 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute3.internal (MEProxy); Thu, 06 Oct 2016 20:26:56 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=JVkoMeQswXhZY3twfKfFIDR9U9M=; b=hTEmBh RMA5+9vaID/rLLq5eD3XyFvp1c58Pm1pSgbNXwxxpt46U1PNmwyHYtLK1dnBnIDf AVysO3B3BbOsvWEomFLyU8iyQEpQ0/rX092FB/iaSDPFqdiipzXaAVIlK7E1pApv iLkOuCQF6TDWqRmxzEhnwigTCl91pHrDIu/3o= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=JVkoMeQswXhZY3t wfKfFIDR9U9M=; b=cxVLX9g6DWQljokWWEmTb30Jcre06RotUIw/zyTMVdMFwN1 zcP0DV9ZfivY6JIHchIRbVLTzC+ys4gWFZ9L5fV40VsotHEoXwBnAZmg6ABPtXUO 60fV4SNIusq3hYNIPLnIpv6wzVZ8ZNZF7ISlQXpWCEwgkLj/jmAl4AGzevwg= X-Sasl-enc: 79ecR0ESqCMnXsfsYgb0qMIkLIVCHHSaCu7AnDWpgo14 1475800016 Received: from [192.168.1.2] (174-21-85-118.tukw.qwest.net [174.21.85.118]) by mail.messagingengine.com (Postfix) with ESMTPA id 2AFD7F2985; Thu, 6 Oct 2016 20:26:56 -0400 (EDT) Subject: Re: row number with in cursor To: Kevin Duffy , pgsql-sql@postgresql.org References: From: Adrian Klaver Message-ID: <81027780-1d91-4d1a-a1ef-7a6cfc77b37b@aklaver.com> Date: Thu, 6 Oct 2016 17:26:55 -0700 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) 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 On 10/06/2016 05:05 PM, Kevin Duffy wrote: > Hello All: > > I need your kind assistance, to learn if it is possible > within a cursor to know what row you are on. What version of Postgres? Are you actually using a CURSOR as defined by plpgsql?: https://www.postgresql.org/docs/9.6/static/plpgsql-cursors.html Looks like you are LOOPing over the results of a function? > Something like this: > > for currDateRate IN currDR( rate_in, start_date ) LOOP > > raise notice ' currDateRate.rate_date: %', currDateRate.rate_date ; > raise notice ' currDateRate.lag_r_value: %', currDateRate.lag_r_value ; > raise notice ' currDateRate.rate_value: %', currDateRate.rate_value ; > raise notice ' currDateRate.overnight_r: %', > currDateRate.overnight_rate_return ; > tr_index := tr_index *( 1+ currDateRate.overnight_rate_return ) ; > raise notice ' tr_index: %',tr_index ; > -- this does NOT work > raise notice ' row number %', currDateRate%ROWNUMBER ; There is no ROWNUMBER in plpgsql(I am assuming you are using that?). > > End LOOP; > > for testing purposes would like to break out after twenty records. > Yes I know I could do a simple counter like this: > > rtn_cnt := rtn_cnt +1; > if rtn_cnt >= 20 then > return rtn_cnt; > END IF; I think you will need to use some variation of the above. Or add an argument to currDR(assuming it is a function) that sets a LIMIT. > > > thamks for your attention to this matter > > KD -- Adrian Klaver adrian.klaver@aklaver.com -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql