Hey,
I'm looking forward for an algorithm for permutations with repetition.
My idea was to fill a table with the different elements to choose from e.g A;B;C and then make a combination of CROSS JOIN. For example like this, if you would select 3 times.
SELECT * FROM "tab1" CROSS JOIN "tab1" CROSS JOIN "tab1";
This works fine so far. Now I wanted to put this in a procedure where the number of selections is the input parameter.
CREATE PROCEDURE "TEST_SYSTEM"."permutation" (
IN numberSelections INT)
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
DEFAULT SCHEMA TEST_SYSTEM
AS
BEGIN
DECLARE loop_index INT := 1;
leftTab = SELECT "VAR1" AS "left" FROM "tab1";
WHILE loop_index < numberSelections DO
rightTab = SELECT "VAR1" AS "right" FROM "tab1";
leftTab = SELECT * FROM :leftTab CROSS JOIN :rightTab;
loop_index = :loop_index - 1;
END WHILE;
END;