3 ms·
Matrices are constructed from arrays of rows, columns, and values. The simplest way to pivot a table into a matrix is to use array_agg() select matrix(array
by michelpp 8y ago
Matrices are constructed from arrays of rows, columns, and values. The simplest way to pivot a table into a matrix is to use array_agg()
select matrix(array_agg(row), array_agg(col), array_agg(val))) from table;
For the inverse operation there are set returning functions called 'matrix_elements_<type>(m)' which return the graph elements as row tuples.
From a table management standpoint, matrices are varlena objects much like arrays. Triggers can be used to call set_element() to keep matrices and tables sync'ed, although like arrays, this has a high re-serialization cost for large arrays. Because of this it's best to modify matrices in bulk operations.