Hygor Knust
07/20/2023, 6:17 PMcreate table country_code_lookup_table (
country_name VARCHAR,
country_code
)
with (
'connector' = 'memory'
);
insert into country_code_lookup_table values (...), ...;
The idea is to create a table to replace a bunch of long CASE statements by joining to this table instead.
I tried using a file table but it doesn’t work well.Martijn Visser
07/20/2023, 7:10 PMHygor Knust
07/20/2023, 7:15 PMSELECT
id,
…
CASE
WHEN country_name = '…' THEN '…'
— repeat for every almost 200 countries
END
FROM source_table_1;
SELECT
id,
…
CASE
WHEN country_name = '…' THEN '…'
— repeat for every almost 200 countries
END
FROM source_table_2;
SELECT
id,
…
CASE
WHEN country_name = '…' THEN '…'
— repeat for every almost 200 countries
END
FROM source_table_3;
I have the option to create an UDF but I don’t want to split the logic.Martijn Visser
07/20/2023, 7:33 PMHygor Knust
07/20/2023, 7:44 PMbirth_country, residence_country, past_country and so on. So doing a UNION all would still require a lot of code.
The current solution is working though, it’s just too cumbersome to work with. Hence the idea of creating a “temporary” table to simplify itMartijn Visser
07/20/2023, 10:03 PMMartijn Visser
07/20/2023, 10:04 PMHygor Knust
07/21/2023, 10:53 AMMartijn Visser
07/21/2023, 12:00 PM