Using return value from DELETE for UPDATE in Postgres
问题 I need to update a table using a value deleted from another table. The situation is a comment vote scorekeeper similar to the one on SO. I'm using python to work the postgres, but that shouldn't make a difference. query=""" UPDATE comment SET score=score-(DELETE FROM history WHERE commentId=%(commentId)s AND userIdentity=%(userIdentity)s RETURNING vote) WHERE commentId=%(commentId)s; """ cursor.execute(query, data) The error arises at (DELETE FROM ; a syntax error arises. I can replace the