0

Here is the query I'm having a problem with:

UPDATE entry SET is_locked_by = NULL
WHERE id IN (
              SELECT cee."entryId" FROM category_entries_entry AS cee
              WHERE cee."categoryId" IN (${descendantsWithParent.map(c => c.id).join()})
              LEFT JOIN category cat ON cee."categoryId" = cat.id WHERE NOT cat.is_locked
            );

Category relates to Entry as ManyToMany. And I want to update all entries where category.is_locked is false.

This query does not seem to work, it seems to ignore the WHERE NOT cat.is_locked.

What is wrong with this query?

2
  • The two WHERE clauses in the inner query look sketchy Commented Aug 17, 2020 at 16:48
  • 1
    join can not be used after where clause. it seems you are mixing function operator of JS in postgres query Commented Aug 17, 2020 at 16:48

1 Answer 1

1

There is no problem with WHERE NOT cat.is_locked as long as is_locked is boolean. You should write your query like this.

UPDATE entry SET is_locked_by = NULL
WHERE id IN (
              SELECT cee."entryId" FROM category_entries_entry cee
              LEFT JOIN category cat ON cee."categoryId" = cat.id
              WHERE NOT cat.is_locked 
              and cee."categoryId" IN ( set of IDs)  -- you can use your statement in your program i. e. (${descendantsWithParent.map(c => c.id).join()}
            );
Sign up to request clarification or add additional context in comments.

2 Comments

Aah yeah seem so. Thank you, lemme check if it works.
your value list should be proper after IN

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.