Created
June 11, 2020 10:42
-
-
Save antichaos/f1c4f5fa2e3056003a435451ccdcfdfb to your computer and use it in GitHub Desktop.
unpivot-postgres.sql
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
SELECT | |
'CyberSecurityIndex' AS "index", | |
"CyberSecurityIndex"."Country" AS "Country", | |
"CyberSecurityIndex"."iso3" AS "iso3", | |
CAST("CyberSecurityIndex"."Year" AS TEXT) AS "Year", | |
t.subindex AS subindex, | |
CAST(t.value AS float) AS value | |
FROM "indices"."009_cybersecurityindex" "CyberSecurityIndex" | |
cross join lateral ( | |
values | |
("CyberSecurityIndex"."National Cyber Security Index", 'National Cyber Security Index'), | |
("CyberSecurityIndex"."Digital Development Level", 'Digital Development Level'), | |
("CyberSecurityIndex"."Difference", 'Difference NCSI-DPL') | |
) as t(value, subindex) | |
UNION | |
SELECT | |
'PressfreeomdIndex' AS "index", | |
"pressfreedomindex"."countryname" as "Country", | |
"pressfreedomindex"."iso3" as "iso3", | |
CAST("pressfreedomindex"."year" AS TEXT) AS "Year", | |
NULL AS "subindex", | |
CAST(indexvalue AS float) AS value | |
FROM "indices"."001_pressfreedomindex" "pressfreedomindex" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment