In PostgreSQL, say I have a table with a column of 2-dimensional array of integers, and another table storing a column of an array of size 2.
CREATE TABLE ta (arr int[][]);
CREATE TABLE tb (pos int[]);
I want to look up an element in 'arr' based on a value found for 'pos'. I've worked out that I can do it this way:
SELECT arr[(SELECT pos[1] FROM tb WHERE ... LIMIT 1)][(SELECT pos[2] FROM tb WHERE ... LIMIT 1)] FROM ta;
However, that requires repeating the same subquery twice. Is there a way to achieve this without having to repeat the subquery for every dimension of 'arr'?
(Context: I have a board with x and y coordinates given by 'arr', and need to access a value stored in that board based on the position of a player or object, given by 'pos'. Any suggestions on a better schema for this are also okay, especially if what I'm asking for above isn't possible.)
arr
has apos
why not put them into a single table?