Skip to content

Instantly share code, notes, and snippets.

@judell
Last active June 10, 2024 04:29
Show Gist options
  • Save judell/5b8cf7d2acc9aa25bc9dfe922d057ec9 to your computer and use it in GitHub Desktop.
Save judell/5b8cf7d2acc9aa25bc9dfe922d057ec9 to your computer and use it in GitHub Desktop.
using suppress_counts_and_repeats

example 1

with data as (
  select
    suppress_and_count_repeats (
      'pipes',
      'pipes_organization_member',
      'org_handle',
      'user_handle, user_id, status',
      array['user_handle', 'user_id', 'status']
    ) as json_data
)
select
  json_data ->> 'display_partition_column' as org_handle,
  (json_data -> 'additional_columns' ->> 0) as user_handle,
  (json_data -> 'additional_columns' ->> 1) as user_id,
  (json_data -> 'additional_columns' ->> 2) as status
from
  data

example 2

with data as (
    select
        suppress_and_count_repeats(
            'pipes',
            'pipes_connection',
            'plugin',
            'identity_handle, handle',
            array['identity_handle', 'handle', 'created_by']
        ) as json_data
)
select
    json_data->>'display_partition_column' as plugin,
    concat(
      json_data->'additional_columns'->>0,
      '/',
      json_data->'additional_columns'->>1
    ) as org_workspace,
    json_data->'additional_columns'->2->>'handle' as conn_created_by
from data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment