PGAdmin 编辑数据
PGAdmin Edit data
我是 Postgres 的新手,似乎无法编辑 table 中的数据。弹出测试框但不允许我更改文本。这个初始 table 没有任何 PK 或 SERIAL。所以我添加了它们,我的 table 定义现在是这样的:
CREATE TABLE public.weather
(
city character varying(80) COLLATE pg_catalog."default",
temp_lo integer,
temp_hi integer,
prcp real,
date date,
id integer NOT NULL DEFAULT nextval('weather_id_seq'::regclass),
CONSTRAINT weather_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.weather
OWNER to postgres;
大概很简单
右键单击您的 table、select View Data/View All Rows
(或其中一种变体)。 window 将允许您编辑数据。然后按 F6 保存更改(感谢 leverglowh 指出)。
右击你的 table, select View/Edit Data
-> All Rows
:
然后在顶栏有一个图标,看起来像一个table,有一个向下的箭头(下图右侧的图标):
图标是灰色的,但仍然有效。
在 pgadmin 4.6 中,图标发生了变化(见屏幕截图):
缩放到图标:
您也可以使用快捷键 F6。
在 table
中有一个带有保存图标的数据库图像,用于保存编辑后的数据
以上解决方案都适用于问题的具体情况,但我发现它们对我不起作用。
原因是我的table没有主键。正如 pgAdmin's official page 所说:
To modify the content of a table, each row in the table must be
uniquely identifiable. If the table definition does not include an OID
or a primary key, the displayed data is read only.
我曾相信包括:
CREATE TABLE IF NOT EXISTS public.mytable(
id INT GENERATED ALWAYS AS IDENTITY, [...]);
会自动指定id为主键。我错了,因此无法在 pgAdmin.
中编辑“mytable”
我输入后:
ALTER TABLE public.mytable
ADD CONSTRAINT mytable_pkey PRIMARY KEY (id);
问题已解决。
我是 Postgres 的新手,似乎无法编辑 table 中的数据。弹出测试框但不允许我更改文本。这个初始 table 没有任何 PK 或 SERIAL。所以我添加了它们,我的 table 定义现在是这样的:
CREATE TABLE public.weather
(
city character varying(80) COLLATE pg_catalog."default",
temp_lo integer,
temp_hi integer,
prcp real,
date date,
id integer NOT NULL DEFAULT nextval('weather_id_seq'::regclass),
CONSTRAINT weather_pkey PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE public.weather
OWNER to postgres;
大概很简单
右键单击您的 table、select View Data/View All Rows
(或其中一种变体)。 window 将允许您编辑数据。然后按 F6 保存更改(感谢 leverglowh 指出)。
右击你的 table, select View/Edit Data
-> All Rows
:
然后在顶栏有一个图标,看起来像一个table,有一个向下的箭头(下图右侧的图标):
图标是灰色的,但仍然有效。
在 pgadmin 4.6 中,图标发生了变化(见屏幕截图):
缩放到图标:
您也可以使用快捷键 F6。
在 table
中有一个带有保存图标的数据库图像,用于保存编辑后的数据以上解决方案都适用于问题的具体情况,但我发现它们对我不起作用。
原因是我的table没有主键。正如 pgAdmin's official page 所说:
To modify the content of a table, each row in the table must be uniquely identifiable. If the table definition does not include an OID or a primary key, the displayed data is read only.
我曾相信包括:
CREATE TABLE IF NOT EXISTS public.mytable(
id INT GENERATED ALWAYS AS IDENTITY, [...]);
会自动指定id为主键。我错了,因此无法在 pgAdmin.
中编辑“mytable”我输入后:
ALTER TABLE public.mytable
ADD CONSTRAINT mytable_pkey PRIMARY KEY (id);
问题已解决。