Skip to content

Instantly share code, notes, and snippets.

RedShift1 / postgres_pivotcursor.sql
Created Jul 6, 2020 — forked from flashpixx/postgres_pivotcursor.sql
postgres - dynamic pivot-table cursor with column array aggregation
View postgres_pivotcursor.sql
--- 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 mypivot;
View test.js
const typeDefs = `
type Comment {
id: Int!,
body: String!,
postId: Int,
authorId: Int,
archived: Boolean
type Post {