*Postgresql version: PostgreSQL 13.5
alter table accounts
add tags jsonb default '[]'::jsonb not null;
select DISTINCT AC.tags
from accounts as AC where account_type = 'TEAM';
this query is returning me this result:
[
{
"tags":[
"adiputra6/frontend"
]
},
{
"tags":[
]
},
{
"tags":[
"data extraction",
".net",
"nlp"
]
},
{
"tags":[
"bootstrap",
"ecommerce",
"mysql",
"paypal",
"shopping cart"
]
},
{
"tags":[
"launcher"
]
},
]
(I am using distinct cause it can have duplicate values inside the json tags, and i need a list without duplicates values)
i have tried the jsonb '->' operator:
select DISTINCT AC.tags->'tags'
from accounts as AC where account_type = 'TEAM';
result from the previous query: [{"?column?":null}]
i would like to get a result of distinct list in a single line like:
tags: {"launcher", "bootstrap","ecommerce","mysql", "paypal","shopping cart"...}
how can i do that ?
found a solution in here but it dosen t work in my case and i can t understand why data looks the same: https://dbfiddle.uk/?rdbms=postgres_12&fiddle=dc11527694d1f7bc642464f6100f49ad
CREATE TABLE
statement). And explain the purpose ofDISTINCT
in your query. It rarely makes sense to apply it to a JSON value. Finally: your query would return a set, but you display a single JSON value. Please clarify.