Answer the question
In order to leave comments, you need to log in
What is the correct way to write a double update?
WITH hide AS
(
UPDATE "TABLE1"
SET
"Value1" = FALSE
WHERE "кое-что" = ANY ($1 :: INT [])
)
UPDATE "TABLE1"
SET
"Value2" = TRUE
WHERE "кое-что" = ANY ($1 :: INT [])
AND NOT EXISTS(
SELECT NULL
FROM "TABLE2"
WHERE "что-то" = "кое-что"
)
AND NOT EXISTS(
SELECT NULL
FROM "TABLE3"
WHERE "что-то" = "кое-что"
)
Answer the question
In order to leave comments, you need to log in
You are greatly mistaken if you think that your cte is being executed sequentially.
https://www.postgresql.org/docs/9.6/static/queries...
You are performing different actions on the same data nugget of the same rows. Do not do it this way. I have no idea what effect this will have.
In addition, you simply rewrite in one simple request
UPDATE "TABLE1"
SET
"Value2" = (NOT EXISTS(
SELECT NULL
FROM "TABLE2"
WHERE "что-то" = "кое-что"
)
AND NOT EXISTS(
SELECT NULL
FROM "TABLE3"
WHERE "что-то" = "кое-что"
))
WHERE "кое-что" = ANY ($1 :: INT [])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question