Have “select for update” block on nonrexisting rows

前端 未结 3 600
深忆病人
深忆病人 2021-02-07 03:24

we have some persistent data in an application, that is queried from a server and then stored in a database so we can keep track of additional information. Because we do not wan

3条回答
  •  你的背包
    2021-02-07 03:43

    I am not sure how select for update handles non-existing rows.

    It doesn't.

    The best you can do is to use an advisory lock if you know something unique about the new row. (Use hashtext() if needed, and the table's oid to lock it.)

    The next best thing is a table lock.

    That being said, your question makes it sound like you're locking way more than you should. Only lock rows when you actually need to, i.e. write operations.

提交回复
热议问题