Reputation: 13327
First, I have this query, which works just fine:
DELETE FROM notifications
WHERE data @> '{"postID": 321}'
RETURNING user_id, read
But then, I use it as a sub-query:
SELECT d.user_id, count(d.user_id)
FROM (
DELETE FROM notifications
WHERE data @> '{"postID": 321}'
RETURNING user_id, read
) as d
WHERE d.read = false
GROUP BY d.user_id
And get this error:
ERROR: syntax error at or near "FROM"
LINE 16: DELETE FROM notifications
^
SQL state: 42601
Character: 245
Upvotes: 0
Views: 35
Reputation: 1271111
Use a CTE:
WITH d as (
DELETE FROM notifications
WHERE data @> '{"postID": 321}'
RETURNING user_id, read
)
SELECT d.user_id, count(d.user_id)
FROM d
WHERE d.read = false
GROUP BY d.user_id
Upvotes: 3