This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Filter an array of events such that there is only one event with each event_id. | |
-- When more than one event with the same event_id, is present, take the latest one. | |
CREATE OR REPLACE FUNCTION dedupe_events_2(events HSTORE[]) RETURNS HSTORE[] AS $$ | |
SELECT array_agg(event) | |
FROM ( | |
-- select first of elements with the same event_id by position in the array, descending. | |
SELECT first_value(event) as event | |
OVER (PARTITION BY (event -> 'event_id')::BIGINT ORDER BY index DESC) | |
FROM ( | |
-- Use unnest instead of generate_subscripts to turn an array into a set. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Do you ever define #method_missing and forget #respond_to? I sure | |
# do. It would be nice if we could do them both at the same time. | |
module MatchMethodMacros | |
def match_method(matcher, &method_body) | |
mod = Module.new do | |
define_method(:method_missing) do |method_name, *args, &blk| | |
if matcher === method_name.to_s | |
instance_exec(method_name, *args, blk, &method_body) | |
else |