From: | Marc Mamin <M(dot)Mamin(at)intershop(dot)de> |
---|---|
To: | Elliot <yields(dot)falsehood(at)gmail(dot)com>, Robert James <srobertjames(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Detecting change in event properties |
Date: | 2013-10-25 19:03:08 |
Message-ID: | B6F6FD62F2624C4C9916AC0175D56D880CE433CA@jenmbs01.ad.intershop.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>Von: pgsql-general-owner(at)postgresql(dot)org [pgsql-general-owner(at)postgresql(dot)org]" im Auftrag von "Elliot [yields(dot)falsehood(at)gmail(dot)com]
>Gesendet: Freitag, 25. Oktober 2013 20:33
>
>On 2013-10-25 13:35, Robert James wrote:
>> On 10/25/13, Robert James <srobertjames(at)gmail(dot)com> wrote:
>>> I have a table of (timed) events, and I'm interested in marking events
>>> whose properties have changed from the previous event.
>>>
>>> I believe this can be done with window functions, but I'm not sure
>>> how. What window function can give me a field from the _previous_
>>> row?
>>>
>>> (To elaborate, I'm interested in:
>>> * Finding field x of the _previous_ row
>>> * Finding field x of the _next_ row
>>> * Finding field x of the _previous_ row that meets a certain criteria
>>> (which the current row may or may not meet)
>>> )
>> The first two are actually trivial - lag(field_x) over (order by [same
>> order as query]) and lead(...).
>>
>> But the last one seems ellusive - How can I find the value of field x
>> on the previous row WHERE a criteria is met? Is it possible to do this
>> at all with a window function?
>>
>>
>
>Maybe a custom aggregate that takes the last item in a set?
Hello,
I would misuse GUC variables for this.
(using the functions current_setting and set_config)
define a set get and switch fuction (I use operators for better readability)
something like:
select 'a' ==> 'foo'
'a'
select 'b' <==> 'foo'
'a'
select <== 'foo'
'b'
and in your query:
SELECT
case when test then col <==> 'foo' else <== 'foo' end
regards,
Marc Mamin
From | Date | Subject | |
---|---|---|---|
Next Message | David Johnston | 2013-10-25 21:22:17 | Re: Detecting change in event properties |
Previous Message | Elliot | 2013-10-25 18:33:34 | Re: Detecting change in event properties |