From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Rishi Ranjan <rishiranjan706(at)gmail(dot)com> |
Cc: | depesz(at)depesz(dot)com, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: pgsql-function |
Date: | 2015-04-14 17:37:20 |
Message-ID: | CAKFQuwaCChuW7KQ89wxVDPWUGP6Cz=DhgcpeEvp-SSC8DPw2pw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Tue, Apr 14, 2015 at 10:31 AM, Rishi Ranjan <rishiranjan706(at)gmail(dot)com>
wrote:
> That will be in this format only. We thinked for normalization part but we
> got clearance that data will be in this format and have to do processing
>
So write a query that uses the lag() window function to create an inline
view having one record per entry with two timestamp fields, both of which
are non-null. Then calculate using that inline view. I suggest you use a
CTE (WITH clause) for the inline view.
The documentation is quite good for window function, CTE (and the related
select statements) and "inserting to another table". If you try and get
stumped I'll be happy to post specific suggestions but if you want an
answer handed to you you will need to wait for someone else to reply.
David J.
> On Apr 14, 2015 10:58 PM, "David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
> wrote:
>
>> On Tue, Apr 14, 2015 at 10:20 AM, Rishi Ranjan <rishiranjan706(at)gmail(dot)com>
>> wrote:
>>
>>>
>>>
>>> we are using version 9.4.
>>> 2) The result of above calculation i need to use in different
>>> calculation . means output of this calculation will let us to determine the
>>> value of some parameters of other equation like below
>>>
>>> y= ((y2-y1)/(x2-x1 ))x+ (y1- (y2-y1)/(x2-x1 ) x1 )
>>>
>>> where x1,y1,x2,y2 parameters are defined and whose value need to be
>>> picked based on value of x (being calculated from above scenario provided
>>> with sample data)
>>>
>>
>> So, is the real data likely to be as perfect as your sample data or do
>> you need something more robust? With the clean data using the lag window
>> function will readily solve your problem. But if you could guarantee this
>> clean of data I would probably have simply created two columns (and yes, I
>> do know what normalization is) for timestamps - one of which can be null:
>> the "second" one) and perform the query directly.
>>
>> David J.
>>
>>
From | Date | Subject | |
---|---|---|---|
Next Message | hubert depesz lubaczewski | 2015-04-14 17:39:46 | Re: pgsql-function |
Previous Message | Rishi Ranjan | 2015-04-14 17:31:55 | Re: pgsql-function |