I need to multiply each element of 2 arrays and project a column which is a array and each element is the product result.
Example:
select * from vetor_query;
Returns:
query_id |pesos |
---------|----------------------------------------------------------------------------------------------------|
1 |{2.0000,0.4150,2.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000} |
And the query:
select * from vetor_documento;
Returns:
doc |pesos |
-------|----------------------------------------------------------------------------------------------------|
d1.txt |{3.0000,0.8301,4.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000} |
d2.txt |{2.0000,0.0000,0.0000,0.0000,2.0000,2.0000,2.0000,2.0000,2.0000,0.0000,0.0000,0.0000,0.0000,0.0000} |
d3.txt |{0.0000,1.0729,0.0000,0.0000,0.0000,0.0000,2.0000,1.0000,0.0000,2.0000,2.0000,0.0000,0.0000,0.0000} |
d4.txt |{0.0000,1.0729,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,0.0000,5.1699,4.0000,4.0000} |
I need to combine both queries(cross join) and produce as a result array of internal product for each doc
and query_id
.
My first attempt was this one:
select vq.query_id, vd.doc, unnest(vq.pesos) * unnest(vd.pesos)
from vetor_query vq
cross join vetor_documento vd;
However, it yields this error:
Functions and operators can take at most one set argument