In PostgreSQL:
nathan=# create table t (i int primary key);
CREATE TABLE
nathan=# begin read only;
BEGIN
nathan=# select * from t for update;
ERROR: cannot execute SELECT FOR UPDATE in a read-only transaction
nathan=# rollback;
ROLLBACK
nathan=# begin read only;
BEGIN
nathan=# select * from t for share;
ERROR: cannot execute SELECT FOR SHARE in a read-only transaction
In CockroachDB:
[email protected]:59592/postgres> create table t (i int primary key);
CREATE TABLE
[email protected]:59592/postgres> begin read only;
BEGIN
[email protected]:59592/postgres OPEN> select * from t for update;
i
-----
(0 rows)
[email protected]:59592/postgres OPEN> select * from t for share;
i
-----
(0 rows)
@nvanbenschoten I would like to work on this issue if no one is looking at it. Thanks!
Hi @manhhiep92, no one is currently looking at this, so it's all yours!
To point you in the right direction, I suspect that this check will take place somewhere in pkg/sql/opt/... tree of packages.
Thanks for the contribution @hiepd!