Last active
October 31, 2022 15:01
-
-
Save fabriziomello/a58a8f911378739081faeae4f0c8ba26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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