小编Abe*_*ker的帖子

如何使执行连接的 Postgres 视图可更新?

我有两张桌子,products并且subscriptions

CREATE TABLE products (
    id bigint NOT NULL,
    title character varying(75),
    description text,
    manufacturer_id bigint,
    created_at timestamp without time zone,
    updated_at timestamp without time zone,
    mpn text,
    visible boolean DEFAULT false NOT NULL
);

CREATE TABLE subscriptions (
    id bigint NOT NULL,
    product_id bigint NOT NULL,
    user_id bigint NOT NULL,
    created_at timestamp without time zone,
    updated_at timestamp without time zone
);
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,我通常需要知道某个产品的订阅者数量,而在应用程序中所有正确位置使用此逻辑是很棘手的。所以我想products用已经包含该信息的视图替换该表。所以我这样做了:

ALTER TABLE ONLY products
  RENAME TO products_raw;

CREATE VIEW products AS …
Run Code Online (Sandbox Code Playgroud)

postgresql join view update

5
推荐指数
1
解决办法
3121
查看次数

标签 统计

join ×1

postgresql ×1

update ×1

view ×1