1

I try update postgresql table using subquery

        UPDATE
            bc
        SET
            (r, w) = ($1, $2)
        WHERE
            bc.sr_id IN (
                UPDATE
                    sr
                SET
                    (r, w) = ($1, $2)
                WHERE
                    si = $3 AND
                    rti = $4 AND
                    fc = $5
                RETURNING sr.id
            )

Why it's returns error?

1
  • 1
    What is the error message? Commented Mar 6, 2013 at 10:32

1 Answer 1

2

You can't chain DML statements like that. You will have to use a writable CTE.

WITH buz AS
(UPDATE foo
SET num=0 WHERE num>5 RETURNING num)
UPDATE bar SET num=0 WHERE num IN
(SELECT num FROM foo);
SELECT * FROM foo;
SELECT * FROM bar;

http://sqlfiddle.com/#!1/513a2/1

Sign up to request clarification or add additional context in comments.

1 Comment

Available as of version 9.1 and a reason to upgrade if you're using an older version.

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.