# ordinalize an integer, whether positive or negative create or replace function ordinalize(x) as ( x::VARCHAR || '''' || if( 11 <= (abs(x) % 100) and (abs(x) % 100) <= 13, 'th', case abs(x) % 10 when 1 then 'st' when 2 then 'nd' when 3 then 'rd' else 'th' end) ); create or replace function task(lst) as ( select list_transform(lst, ix -> ordinalize(ix)) .array_to_string(' ') ); ## Examples .header off .maxwidth 300 .mode list select task(range(-5, -1)); select task(range(0,26)); select task(range(250,266)); select task(range(1000,1026));