Skip to content

Instantly share code, notes, and snippets.

@mekhami
Created October 21, 2019 14:39
Show Gist options
  • Save mekhami/2e0c3549d4fe6081764822d4ecbb53a9 to your computer and use it in GitHub Desktop.
Save mekhami/2e0c3549d4fe6081764822d4ecbb53a9 to your computer and use it in GitHub Desktop.
create or replace function get_partitions(spec text, conditions text)
returns table (id bigint, partition jsonb)
as
$body$
select j.ord, j.value
from subscriptions_fulfillmentplan plan, jsonb_array_elements(plan.new_segments) segment, jsonb_array_elements(segment->'partitions') with ordinality as j(value,ord)
where plan.spec = spec
and segment->'rule'->>'conditions' = conditions
$body$
language sql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment