sosedoff / pgweb

Cross-platform client for PostgreSQL databases
https://sosedoff.github.io/pgweb
MIT License
8.64k stars 733 forks source link

Fix bug with UPDATE/DELETE and RETURNING clause #556

Closed tanyongzhi closed 2 years ago

tanyongzhi commented 2 years ago

This problem stems from the client having to use Exec() when no return value is expected (to get the number of rows affected by the update/delete), and Queryx() (to get the result of a RETURNING clause) when we expect rows to be returned. There is no clean way to differentiate the two cases to my knowledge, because (1) we have no way of accurately determining if a delete/update query will return any rows before running it, and (2) we cannot run both Exec() and Queryx() one after another because we cannot assume the updates/deletes are idempotent.

I recognize that this approach seems hacky, and is not 100% accurate (eg. it fails when a column is named "returning"). However, it seems to be the best way to me to tackle this issue. I appreciate any other insights regarding this.

Fixes #553