I have a table that contains arrays of integers. These integers are code names for quantities. Each quantity (hence integer) has also an associated index in a bigger array.
For example
Row in Table A {5,6,7,8,9}
Table B contains the look up for the indices
Val Idx 5 10 6 1 7 9 8 2 9 3
What I would like to do is to create a row in table C for all rows in table A that contains a vector where the indices corresponding to the elements in the A table are 1 and the remainder are 0 like
{ 0,1, 1,0,0,1,0,0,1,1}
where the maximum length of this vector is known
How can I best do it in Postgresql? Should I loop using PL/PgSQL?