1

我尝试使用子查询更新 postgresql 表

        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
            )

为什么它返回错误?

4

1 回答 1

2

您不能像这样链接 DML 语句。您将不得不使用可写的 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

于 2013-03-06T10:36:31.567 回答