Skip to content

Instantly share code, notes, and snippets.

View flashpixx's full-sized avatar

Philipp Kraus flashpixx

View GitHub Profile
@flashpixx
flashpixx / postgres_pivotcursor.sql
Created May 8, 2018 14:29
postgres - dynamic pivot-table cursor with column array aggregation
--- description: creates a dynamic temporary pivot table:
--- first argument is the name of the pivot-table
--- second the data select
--- third an array of key fields
--- fourth an array of pivot columns
--- fifth an array of returning fields
---
--- usage (example): select * from pivottable( 'mypivot', 'select * from mydata', array['id', 'name', 'description'], array['parametername'], array['parametervalue::text', 'parametervaluetext'] ); fetch all from myprivot;
CREATE OR REPLACE FUNCTION pivottable(

Keybase proof

I hereby claim:

  • I am flashpixx on github.
  • I am flashpixx (https://keybase.io/flashpixx) on keybase.
  • I have a public key ASDmb--ZeOalhLciL0-la1ZqVuVFfMarMtLzkJthwhMqEQo

To claim this, I am signing this object:

import javax.annotation.Nonnull;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* common functions