Skip to content

Instantly share code, notes, and snippets.

View Bennyelg's full-sized avatar

Benny Elgazar Bennyelg

View GitHub Profile
@Bennyelg
Bennyelg / 20171104_2.md
Created February 7, 2019 07:49 — forked from shotahorii/20171104_2.md
(un)pivot on Presto

Pivot

Query
SELECT
  uid,
  kv['c1'] AS c1,
  kv['c2'] AS c2,
  kv['c3'] AS c3
FROM (
@Bennyelg
Bennyelg / plpythonu.sql
Created February 2, 2019 20:28 — forked from rturowicz/plpythonu.sql
postgresql: example use of python procedural language
-- query with stored plan
CREATE or replace FUNCTION pybench1(id int) RETURNS text AS '
if (SD.has_key("plan")):
plan = SD["plan"]
else:
plan = plpy.prepare("SELECT * FROM pagetimer pt, pagebrowser pb WHERE pt.idtimer = $1 and pt.idtimer = pb.idtimer", ["int4"])
SD["plan"] = plan
rec = plpy.execute(plan, [id])
if (rec.nrows() > 0):