如何在 postgreSQL pgAdmin 中插入一行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22755230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to insert a row in postgreSQL pgAdmin?
提问by Ila
I am new to postgreSQL. Is there any way to insert row in postgreSQL pgAdmin without using SQL Editor (SQL query)? Pls help me, thanks.
我是 postgreSQL 的新手。有没有办法在不使用 SQL 编辑器(SQL 查询)的情况下在 postgreSQL pgAdmin 中插入行?请帮助我,谢谢。
采纳答案by KarelG
You can do that without the SQL editor, but it's better to do this by queries.
您可以在没有 SQL 编辑器的情况下执行此操作,但最好通过查询执行此操作。
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.
虽然在 pgAdmin 中有一个选项,您可以单击该选项以拥有一个类似 excel 的窗口,您可以在其中添加和更新表中的数据,而无需使用 SQL 语言。请先选择要添加行的表格,然后单击下面的下一个图标。
回答by G?del77
回答by Rutger Hofste
回答by niaomingjian
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.
禁止无主键编辑表数据
如果你的表没有主键或OID,你只能查看数据。
没有主键的“编辑数据”工具无法插入新行和更改现有行。
回答by cm1
The accepted answer is related to PgAdmin 3 which is outdated and not supported. For PgAdmin 4and above, the application is running in the browser.
接受的答案与过时且不受支持的 PgAdmin 3 相关。对于PgAdmin 4及更高版本,应用程序在浏览器中运行。
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.
要修改表的内容,表中的每一行都必须是唯一可识别的。如果表定义不包含 OID 或主键,则显示的数据是只读的。请注意,无法编辑视图;不支持可更新视图(使用规则)。
1- Add primary key
1- 添加主键
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.
通过在 pgAdmin4 图例中单击它来展开您的表属性。右键单击“约束”,选择“创建”-->“主键”以定义主键列。
2- View the data in excel like format
2-以excel格式查看数据
Browser view, right-click on your table --> select View/Edit Data --> All Rows
浏览器视图,右键单击您的表格 --> 选择查看/编辑数据 --> 所有行
3- Add new row / Edit data
3- 添加新行/编辑数据
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.
在最后一行下方表格底部的“数据输出”选项卡上,将有一个空行,您可以在其中以类似 excel 的方式输入新数据。如果您想进行更新,您还可以双击任何单元格并更改其值。
4- Save the changes
4- 保存更改
Click on the 'Save' button on the menu bar near the top of the data window.
回答by cm1
Use INSERT
:
使用INSERT
:
INSERT INTO tablename (field1, field2) values ('value1', 2);