Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

pgAdmin 4 will not let you edit rows in the data grid

ErrorCells in View/Edit Data cannot be edited

Short answer

pgAdmin edits a row only when it can find that exact row again. A table with no primary key or OID opens read-only, and a Query Tool result is editable only when it selects all primary key columns directly from one table, without renaming them. Add a primary key, or change the query.

  • Applies to pgAdmin 4, PostgreSQL 16, PostgreSQL 17
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the table has a primary key.

    SELECT conname FROM pg_constraint
    WHERE conrelid = 'public.my_table'::regclass AND contype = 'p';
  2. 2Match what you see, then jump to its fix

    1. 1The query above returns no row, and View/Edit Data opens read-onlyThe table has no primary keyFix
    2. 2Only some columns have lock icons, or all of them do, in a SELECT resultThe Query Tool result is not an updatable result setFix

What does the error look like?

  • Cells in View/Edit Data cannot be edited
  • Lock icons in the column headers of the Query Tool result

Cause 1 of 2

The table has no primary key

1Check

pgAdmin documents that a table without an OID or a primary key shows its data read-only, because rows cannot be told apart.

\d public.my_table

2Fix

Add a primary key on a column that is unique and never null, then reopen the data grid. If no column fits, add an identity column.

ALTER TABLE public.my_table ADD PRIMARY KEY (id);
-- or, with no suitable column:
ALTER TABLE public.my_table ADD COLUMN id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY;

3Verify

Open View/Edit Data again and double-click a cell.

-- the cell opens for editing; press Save Data to commit

Confirmed by pgadmin.org

Did this fix it?

Cause 2 of 2

The Query Tool result is not an updatable result set

1Check

A result is editable only if all primary key columns of the table are selected. Only columns taken straight from the table are editable; renamed columns, columns selected twice and computed ones are read-only. Pencil and lock icons in the headers show which is which.

SELECT id, name AS title, upper(name) FROM public.my_table;

2Fix

Select the primary key and the plain columns without aliases, from one table.

SELECT id, name, email FROM public.my_table WHERE id < 100;

3Verify

The column headers now show pencil icons.

-- edit a cell, then press Save Data

Confirmed by pgadmin.org

Did this fix it?

How do I stop it coming back?

  • Give every table a primary key when you create it.
  • Use the Query Tool for edits only on single-table queries that include the key columns.
  • With auto-commit off, remember that saved edits stay in the open transaction until you commit it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.