I have some symbols and I need to arrange them and determine the number of ways in which they can be arranged:
(x11,x12,x13); (x21,x22,x23); (y11,y12,y13); (y21, y22, y23); (y31,y32,y33); (z11, z12, z13)
Note that while calculating the permutations, the order within the round brackets must be maintained. For instance, one possible order could be x11, x21, x12, x22, x13, x23 ... Note that here x13 occurs after x12 which occurs after x11.
How do we determine the total number of permutations with this restriction?
One way would be to create 2 tables and do a cartesian join:
create table letters (letter char(1));
create table numbers (num numeric);
insert into letters values ('A');
insert into letters values ('B');
insert into letters values ('C');
insert into numbers values (1);
insert into numbers values (2);
insert into numbers values (3);
select letter, num
from letters, numbers;
With more code, you can do this without the "hard tables" and instead hardcode the data within an array, then have postgres use it the same as a table-- just depends on how much data we're talking about.
Then again, I could be completely misunderstanding the problem you're trying to solve as the number of permutations in my example is "number of rows in letters table" times "Number of rows in numbers table"