0

This seems like it would be straightforward to do but I just can not figure it out. I have a query that returns an ARRAY of strings in one of the columns. I want that array to only contain unique strings. Here is my query:

SELECT
    f."_id",
    ARRAY[public.getdomain(f."linkUrl"), public.getdomain(f."sourceUrl")] AS file_domains,
    public.getuniqdomains(s."originUrls", s."testUrls") AS source_domains
FROM
    files f
LEFT JOIN
    sources s
ON
    s."_id" = f."sourceId"

Here's an example of a row from my return table

_id file_domains source_domains
2574873 {cityofmontclair.org,cityofmontclair.org} {cityofmontclair.org}

I need file_domains to only contain unique values, IE a 'set' instead of a 'list'. Like this:

_id file_domains source_domains
2574873 {cityofmontclair.org} {cityofmontclair.org}

1 Answer 1

1

Use a CASE expression:

CASE WHEN public.getdomain(f."linkUrl") = public.getdomain(f."sourceUrl")
     THEN ARRAY[public.getdomain(f."linkUrl")]
     ELSE ARRAY[public.getdomain(f."linkUrl"), public.getdomain(f."sourceUrl")]
END
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.