Skip to content

Instantly share code, notes, and snippets.

View benhannel's full-sized avatar

Ben Hannel benhannel

  • Stanford University
View GitHub Profile
@benhannel
benhannel / json_join.sql
Created July 31, 2019 22:36
Using SQL to join the nested JSON data with CSV data
%%time
%%sql
WITH
-- # compute application statistics, MAU and percent change in MAU.
appStats AS
(
SELECT
rows.r[2][1]."name" AS app,
@benhannel
benhannel / json_populate_record.sql
Created July 31, 2019 23:30
Populating a table from a JSON string
INSERT INTO company_regions
SELECT *
FROM json_populate_record(NULL::company_regions,
'{"region_id":"10","company_regions":"British Columbia","country":"Canada"}')
INSERT INTO company_regions
SELECT *
FROM json_populate_record(NULL::company_regions,
'{"region_id":"10","company_regions":"British Columbia","country":"Canada"}')
@benhannel
benhannel / json_in_postgres.sql
Created July 31, 2019 23:34
Extracting fields from JSON with Postgres
SELECT
division_info->>'division_id' AS id,
division_info->>'division_name' AS name,
division_info->>'division_lead' AS lead
FROM
company_divisions
@benhannel
benhannel / gist:32adb299741812909b0924efa0bb694b
Created November 28, 2020 17:46
Red cross blood donation search
import requests
import json
import requests_cache
import datetime
requests_cache.install_cache('blood_cache')
def get_drives():
headers = {
'content-type': 'application/json'