I have a table with a couple of 100 columns on which I want to use the GREATEST
function. How can I prevent putting each and every column name into the query?
The columns on which I want to use GREATEST
have a common prefix in case this might help.
That's how I am doing it now.
CREATE TEMP TABLE foo (id int, cc_a int, cc_b int, cc_c int);
INSERT INTO foo VALUES (3, '1', '2', '3'), (4, '15', '4', '100');
SELECT id, GREATEST(cc_a, cc_b, cc_c) FROM foo