How to make function in postgres that would take string or array and return all combinations of some length?
For example you have ABC and you want to get combinations with 2 characters, the result shoul be:
AB
AC
BC
Thank you in advance for your help.
Result:
Unfortunately I cannot find a way to avoid the double string constant. (but the whole thing could be packed into a function) If there are no duplicate characters (or you want to suppres them) you could do the anti-join on the str instead of the idx.
UPDATE (hint from ypercube) It appears that the OP wants the strings to be concatenated. So be it::
Results:
UPDATE2: (here comes the recursive thingy…)
Results 3: