据我所知,文档中的以下定义是等效的:
create table foo (
id serial primary key,
code integer,
label text,
constraint foo_uq unique (code, label));
create table foo (
id serial primary key,
code integer,
label text);
create unique index foo_idx on foo using btree (code, label);
Run Code Online (Sandbox Code Playgroud)
但是,您可以在注释中阅读:向表中添加唯一约束的首选方法是ALTER TABLE ... ADD CONSTRAINT.使用索引来强制执行唯一约束可以被视为不应直接访问的实现细节.
这只是一个好风格的问题吗?选择其中一种变体(例如性能)的实际后果是什么?
我的应用程序使用悲观锁定。当用户打开用于更新记录的表单时,应用程序执行此查询(表名是示例性的):
begin;
select *
from master m
natural join detail d
where m.master_id = 123456
for update nowait;
Run Code Online (Sandbox Code Playgroud)
该查询锁定一个主行和几个(到几十个)明细行。交易一直持续到用户确认或取消更新。
我需要知道哪些行(至少是主行)被锁定。我挖掘了文档和 postgres wiki 没有成功。
是否可以列出所有锁定的行?