Sample Header Ad - 728x90

Build array from boolean columns

2 votes
2 answers
1387 views
I have columns like role1, role2, role3, etc. They are all booleans. I would like to create a view on this table, that has a roles column of type text[]. If the columns were TRUE, FALSE, TRUE, the view would contain ["role1", "role3"]. Is there any good way to do this that doesn't explode into a ton of CASE WHEN´s? To clarify, I'd be fine with O(n) with CASE WHEN, but not O(2^n) which is what it currently seems to need. :)
Asked by lurf jurv (330 rep)
Feb 23, 2020, 12:22 AM
Last activity: Mar 28, 2022, 12:46 AM