0

I have a simple postgresql table defined as follows:

CREATE TABLE t_s (
    a integer,
    b integer
);

If I do a simple update statement UPDATE t_s SET a=1 WHERE b=1 I get an error:

Chyba SQL:

ERROR:  syntax error at or near "SET"
LINE 1: SELECT COUNT(*) AS total FROM (UPDATE t_s SET a=1 WHERE b=1)...
                                                  ^

Ve výrazu:
SELECT COUNT(*) AS total FROM (UPDATE t_s SET a=1 WHERE b=1) AS sub

Is there anything that can go wrong with this statement? I can't see any reason for this error. I use PostgreSQL 9.1.6.

1
  • Your error message shows that you are NOT running the UPDATE you claim to be running. Commented Jan 24, 2013 at 11:28

1 Answer 1

1

You need a common table expression for this:

WITH cte AS (
    UPDATE t_s SET a=1 WHERE b=1 RETURNING a
)
SELECT COUNT(*) AS total FROM cte;

Data modifying statements are available as of version 9.1

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.