暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.

1618

To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.

原因是发布订阅的表没有主键,不能进行update和delete操作。

Q

MogDB=#update pub_sub set name = 'e' where name = 'd'; ERROR: cannot update table "pub_sub" because it does not have a replica identity and publishes updates HINT: To enable updating the table, set REPLICA IDENTITY using ALTER TABLE.

pub端

MogDB=#\d+ pub_sub Table "public.pub_sub" Column | Type | Modifiers | Storage | Stats target | Description --------+-------------------+-----------------------------------------------------+----------+--------------+------------- i | integer | not null default nextval('pub_sub_i_seq'::regclass) | plain | | name | character varying | | extended | | Has OIDs: no Options: orientation=row, compression=no

sub端

MogDB=#\d pub_sub Table "public.pub_sub" Column | Type | Modifiers --------+-------------------+----------------------------------------------------- i | integer | not null default nextval('pub_sub_i_seq'::regclass) name | character varying |

A

pub,sub两端添加主键

MogDB=#create unique index concurrently i_pk on pub_sub(name); CREATE INDEX MogDB=#alter table pub_sub add CONSTRAINT pk_pub_sub primary key using index i_pk; NOTICE: ALTER TABLE / ADD CONSTRAINT USING INDEX will rename index "i_pk" to "pk_pub_sub" ALTER TABLE

pub端

MogDB=#select * from pub_sub; i | name ---+------ 1 | a 1 | b 6 | c 7 | d (4 rows) MogDB=#update pub_sub set i=8 where name = 'd'; UPDATE 1 MogDB=#select * from pub_sub; i | name ---+------ 1 | a 1 | b 6 | c 8 | d (4 rows)

sub端

MogDB=#select * from pub_sub; i | name ---+------ 1 | a 1 | b 6 | c 8 | d (4 rows) MogDB=#
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论