How to insert a row in postgreSQL pgAdmin?
PostgresqlPostgresql Problem Overview
I am new to postgreSQL. Is there any way to insert row in postgreSQL pgAdmin without using SQL Editor (SQL query)?
Postgresql Solutions
Solution 1 - Postgresql
The accepted answer is related to PgAdmin 3 which is outdated and not supported. For PgAdmin 4 and above, the application is running in the browser.
After you create your table, you have to make sure that your table has a primary key otherwise you couldn't edit the data as mentioned in the official documentation.
> 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. Note that views > cannot be edited; updatable views (using rules) are not supported.
1- Add primary key
Expand your table properties by clicking on it in the pgAdmin4 legend. Right-click on 'Constraints', select 'Create' --> 'Primary Key'to define a primary key column.
2- View the data in excel like format
Browser view, right-click on your table --> select View/Edit Data --> All Rows
3- Add new row / Edit data
On the Data Output tab at the bottom of the table below the last row, there will be an empty row where you can enter new data in an excel-like manner. If you want to make updates you can also double click on any cell and change its value.
4- Save the changes
Click on the 'Save' button on the menu bar near the top of the data window.
Solution 2 - Postgresql
I think some answers don't provide an answer to the original question, some of them insert records but with SQL statements and the OP clearly said WITHOUT, so I post the right answer: (Step by Step)
Solution 3 - Postgresql
Alternatively you can use the query tool:
INSERT INTO public.table01( name, age) VALUES (?, ?);
use the lightning icon to execute.
Solution 4 - Postgresql
You can do that without the SQL editor, but it's better to do this by queries.
Although, in pgAdmin, there is an option which you can click to have an excel-like window where you can add and update data in a table without using SQL language. Please select a table which you want to add a row first and click on the next icon here below.
Solution 5 - Postgresql
Editing table data without primary key is forbidden
If your tables don't have a primary key or OIDs, you can view the data only.
Inserting new rows and changing existing rows isn't possible for the Edit Data tool without primary key.
Solution 6 - Postgresql
Use INSERT
:
INSERT INTO tablename (field1, field2) values ('value1', 2);
Solution 7 - Postgresql
All the above are correct answers. I just want to add that : When u create a table, make sure u have atleast one column as PRIMARY_KEY. Then, just follow the GUI : View/Edit data. U can add row as the last row of the table
Solution 8 - Postgresql
on pgAdmin 4, right-click on the table and use the item like below. You can also use that script in the background.
Finally, to watch the inserted data do like below. You can also use that script in the background.
Solution 9 - Postgresql
As an update, the icon for the save button is different in pgAdmin 4.
This is how the menu should look after right-clicking on the table you want to insert into and hovering over "View/Edit Data".
After adding rows, either press F6 (on Ubuntu) or click the icon that looks like a stack of discs (database icon) with a lock on it.
Zoomed in:
Wide View: