The point is that I have each asset to have its labels, that is, number 6 to have in a column 1,5
, and asset 1 to have 1,3,5
. Putting literally twice asset_tag.tag_id
copies the same number from that row and separates it by a comma.
"image" is this:
CREATE VIEW imagen as
SELECT asset_tag.asset_id FROM asset_tag GROUP BY asset_tag.asset_id ;
SELECT asset_tag.asset_id, concat_ws(',',asset_tag.tag_id,asset_tag.tag_id) AS etiqueta
FROM public.asset_tag
-- JOIN PUBLIC.imagen ON asset_tag.asset_id = imagen.asset_id
-- WHERE imagen.asset_id = asset_tag.asset_id
GROUP BY asset_tag.asset_id,asset_tag.tag_id
-- HAVING asset_tag.asset_id = imagen.asset_id
;
asest_id 1 1 1 6 6
tag_id 1 3 5 1 2
Let it show in tag_id 1,3,5
for asset_id 1 , and in the case of asset_id 6 let it come out 1,2
.
The data is of type integer.
I have to get through a subquery but I don't see it.
Given that you want to concatenate rows of the same column , and not different columns (which is what you do when you use
CONCAT_WS()
), what you would really be looking for is to use the aggregation functionARRAY_AGG
inside theARRAY_TO_STRING
.According to the documentation :
ARRAY_AGG()
collects all input values, including nulls, into an array. DocumentationARRAY_TO_STRING()
converts each element of the array to its text representation, and concatenates them by the delimiting string. DocumentationSo, applying it to your case:
Produces the following output:
It should be noted that this output occurred with the following statements: