Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yhyzp-0007wx-VY for pgsql-sql@arkaria.postgresql.org; Tue, 14 Apr 2015 11:27:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yhyzo-00034x-8j for pgsql-sql@arkaria.postgresql.org; Tue, 14 Apr 2015 11:27:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yhyzn-00034q-05 for pgsql-sql@postgresql.org; Tue, 14 Apr 2015 11:27:11 +0000 Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Yhyzi-00055j-Vz for pgsql-sql@postgresql.org; Tue, 14 Apr 2015 11:27:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20140207; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To:Message-ID:Subject:Cc:To:Sender:From:Date; bh=T4aCBg8V+iWdNkkBQCPIO4mlrrwEcbH+cj63Y94cAac=; b=Q4d71qJQDPYSoVe4ucTbz/O3ypcL9JCtk/tKKjXwrIcXG6e9PykbOvrnez3YtWLDyhn7ARX2xUKARlPXluJ0xnGqg7QFwM2LRejo0rjpQhvnXgV4su4gMMDL2ffC3sfw; Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by depesz.com with esmtpa (Exim 4.84) (envelope-from ) id 1Yhyzf-0005yI-Sq; Tue, 14 Apr 2015 13:27:03 +0200 Date: Tue, 14 Apr 2015 13:27:03 +0200 From: hubert depesz lubaczewski To: Rishi Ranjan Cc: pgsql-sql@postgresql.org Subject: Re: pgsql-function Message-ID: <20150414112703.GB2224@depesz.com> Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.0 (--) 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 Tue, Apr 14, 2015 at 03:39:38AM -0700, Rishi Ranjan wrote: > i have data like below and where ap_key is same for two different > first_occurence column . here i need to write a function which can > calculate the difference of two timestamp values for a Ap_Key and then with > difference it should multiply the severity 1. Why does it have to be a function? Can't it simply be a query? 2. Which pg version do you use? 3. Which severity to use? from the earlier FIRSTOCCURRENCE, or later, or simply higher/lower SEVERITY? Basically what you're looking for is most likely some group by with min/max. depesz -- The best thing about modern society is how easy it is to avoid contact with it. http://depesz.com/ -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql