Jonnny
Jonnny

Reputation: 5039

PGAdmin Edit data

I'm new to Postgres and can't seem to edit the data in the table. The test box pops up but doesn't allow me to change the text. This initial table didn't have any PK or SERIAL. So I added them and my table definition is now this:

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;

It's probably very simple

Upvotes: 48

Views: 63946

Answers (6)

Ravuthz
Ravuthz

Reputation: 79

There are 2 ways to save updated data in PGAdmin:

  1. Using shortcut key: F6
  2. Using button in image above

enter image description here

Upvotes: 0

RdC1965
RdC1965

Reputation: 582

The above solutions all work for the specific case of the question, but I found that they did not work for me.

The reason is that my table did not have a primary key. As said on 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.

I had believed that including:

CREATE TABLE IF NOT EXISTS public.mytable(
    id INT GENERATED ALWAYS AS IDENTITY, [...]);

would automatically assign id as the primary key. I was wrong and thus could not edit "mytable" in pgAdmin.

Once I entered:

ALTER TABLE public.mytable
ADD CONSTRAINT mytable_pkey PRIMARY KEY (id);

The problem was solved.

Upvotes: 3

Hari
Hari

Reputation: 137

PgAdmin Save

There is an image like Database with Save icon to save the edited data in the table

Upvotes: 4

Melchia
Melchia

Reputation: 24234

With pgadmin 4.6 the icon has changed (see screenshot):

save data icon

a zoom to the icon:

save data icon zoom

You can also use the shortcut F6.

Upvotes: 22

langlauf.io
langlauf.io

Reputation: 3191

Right-click on your table, select View/Edit Data -> All Rows:

enter image description here

Then there is an icon in the top bar, looking like a table with an arrow pointing down (the icon on the right of the screenshot below):

The icon on the right in the picture.

The icon is gray but works nevertheless.

Upvotes: 10

Adam Benson
Adam Benson

Reputation: 8532

Right-click on your table, select View Data/View All Rows (or one of the variants). That window will let you edit the data. Then press F6 to save changes (with thanks to leverglowh for pointing that out).

Upvotes: 113

Related Questions