Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
Snowpocalypse Wow…

Stand Up [NY] 02/08/13: Snowpocalypse Wow… or the Snowpocalypse That Wasn’t
Johnny Mukai & Daniel Grippi

Interestings

Rake::Task[:name].enhance

(from Dave Goddard)

If you wish to change the pre-requisites for rake tasks, or add functions to run after them, then you can use

Rake::Task[:name].enhance(PRE-REQS) do
STUFF AFTER
end

Window Function: lead and lag

(also from Dave Goddard)

If you have records with only start dates, and you want start and end dates, there is a great window function called "lead", which will give you the next value in the group. eg.

id | person | start |
1 | 1 | 123 |
2 | 1 | 456 |
3 | 2 | 234 |
4 | 2 | 567 |

then running

SELECT id, person, start, lead(start) OVER(partition by person ORDER BY start ASC) as ended;

will return

id | person | start | ended |
1 | 1 | 123 | 456 |
2 | 1 | 456 | NULL |
3 | 2 | 234 | 567 |
4 | 2 | 567 | NULL |

PS. using postgresql 9.2 ranges can make the answer even more fun.

Comments
Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *