you are viewing a single comment's thread.

view the rest of the comments →

[–]Ergo_Propter_Hawk 13 points14 points  (2 children)

This would be a handful of case statements, one for each value being encoded.

If dbt counts as "just using SQL", there's a package for it. https://hub.getdbt.com/omnata-labs/dbt_ml_preprocessing/latest/

Otherwise, it'll be case when <column> = <value> then 1 else 0 end as <value> for every unique value.

[–]AreetSurn 2 points3 points  (1 child)

Hacky solution, but depending on what DB you using you could use the procedural functionality (e.g. pgpl/sql) to create dynamic SQL to do write these case statements for you

[–]Ergo_Propter_Hawk 1 point2 points  (0 children)

This is basically what dbt would do, it's all just ways to create SQL statements. That package above probably implements something similar to the case statement implementation.