CREATE EXTENSION plpython3u;

CREATE FUNCTION text_pairs(list TEXT[])
RETURNS SETOF TEXT[]
LANGUAGE plpgsql AS
$$
DECLARE
    x TEXT;
    y TEXT;
BEGIN
    for x, y in(
        SELECT *
        FROM unnest(list) a 
        CROSS JOIN unnest(list) b 
        WHERE a > b)
    LOOP
        RETURN NEXT ARRAY [x, y];
    END LOOP;
END;
$$;


CREATE FUNCTION int_pairs(list INTEGER[])
RETURNS SETOF INTEGER[]
LANGUAGE plpgsql AS
$$
DECLARE
    x INTEGER;
    y INTEGER;
BEGIN
    for x, y in(
        SELECT *
        FROM unnest(list) a
        CROSS JOIN unnest(list) b
        WHERE a > b)
    LOOP
        RETURN NEXT ARRAY [x, y];
    END LOOP;
END;
$$;