Skip to content

Instantly share code, notes, and snippets.

@fabriziomello
Last active October 31, 2022 15:01
Show Gist options
  • Save fabriziomello/a58a8f911378739081faeae4f0c8ba26 to your computer and use it in GitHub Desktop.
Save fabriziomello/a58a8f911378739081faeae4f0c8ba26 to your computer and use it in GitHub Desktop.
-- git@github.com:pramsey/pgsql-http.git
CREATE EXTENSION http;
WITH dados AS (
SELECT
content::jsonb AS obj, 1::integer AS turno
FROM
http_get('https://resultados.tse.jus.br/oficial/ele2022/544/dados-simplificados/br/br-c0001-e000544-r.json')
UNION
SELECT
content::jsonb AS obj, 2::integer AS turno
FROM
http_get('https://resultados.tse.jus.br/oficial/ele2022/545/dados-simplificados/br/br-c0001-e000545-r.json')
),
cand AS (
SELECT jsonb_array_elements(obj->'cand') AS obj, turno FROM dados
)
SELECT obj->>'nm' AS "Candidato", (obj->>'vap')::int AS "Votos", (replace(obj->>'pvap', ',', '.'))::numeric AS "%"
FROM cand
WHERE turno = 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment