PostgreSQL 8.1.23 Documentation | ||||
---|---|---|---|---|
Prev | Fast Backward | Fast Forward | Next |
INSERT INTO table [ ( column [, ...] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) | query }
INSERT inserts new rows into a table. One can insert a single row specified by value expressions, or several rows as a result of a query.
The target column names may be listed in any order. If no list of column names is given at all, the default is all the columns of the table in their declared order; or the first N column names, if there are only N columns supplied by the VALUES clause or query. The values supplied by the VALUES clause or query are associated with the explicit or implicit column list left-to-right.
Each column not present in the explicit or implicit column list will be filled with a default value, either its declared default value or null if there is none.
If the expression for any column is not of the correct data type, automatic type conversion will be attempted.
You must have INSERT privilege to a table in order to insert into it. If you use the query clause to insert rows from a query, you also need to have SELECT privilege on any table used in the query.
The name (optionally schema-qualified) of an existing table.
The name of a column in table. The column name can be qualified with a subfield name or array subscript, if needed. (Inserting into only some fields of a composite column leaves the other fields null.)
All columns will be filled with their default values.
An expression or value to assign to the corresponding column.
The corresponding column will be filled with its default value.
A query (SELECT statement) that supplies the rows to be inserted. Refer to the SELECT statement for a description of the syntax.
On successful completion, an INSERT command returns a command tag of the form
INSERT oid count
The count is the number of rows inserted. If count is exactly one, and the target table has OIDs, then oid is the OID assigned to the inserted row. Otherwise oid is zero.
Insert a single row into table films:
INSERT INTO films VALUES ('UA502', 'Bananas', 105, '2025-08-08', 'Comedy', '82 minutes');
In this example, the len column is omitted and therefore it will have the default value:
INSERT INTO films (code, title, did, date_prod, kind) VALUES ('T_601', 'Yojimbo', 106, '2025-08-08', 'Drama');
This example uses the DEFAULT clause for the date columns rather than specifying a value:
INSERT INTO films VALUES ('UA502', 'Bananas', 105, DEFAULT, 'Comedy', '82 minutes'); INSERT INTO films (code, title, did, date_prod, kind) VALUES ('T_601', 'Yojimbo', 106, DEFAULT, 'Drama');
To insert a row consisting entirely of default values:
INSERT INTO films DEFAULT VALUES;
This example inserts some rows into table films from a table tmp_films with the same column layout as films:
INSERT INTO films SELECT * FROM tmp_films WHERE date_prod < '2025-08-08';
This example inserts into array columns:
-- Create an empty 3x3 gameboard for noughts-and-crosses -- (these commands create the same board) INSERT INTO tictactoe (game, board[1:3][1:3]) VALUES (1,'{{"","",""},{"","",""},{"","",""}}'); INSERT INTO tictactoe (game, board) VALUES (2,'{{,,},{,,},{,,}}');
INSERT conforms to the SQL standard. The case in which a column name list is omitted, but not all the columns are filled from the VALUES clause or query, is disallowed by the standard.
Possible limitations of the query clause are documented under SELECT.
大腿酸痛什么原因 | 脾虚湿盛吃什么药 | pc是什么 | 天天睡觉做梦是什么原因 | 排卵期出血有什么症状 |
梦见自己相亲是什么意思 | 拔完智齿后需要注意什么 | 骨肉瘤是什么病 | 同人文什么意思 | 石家庄有什么好玩的景点 |
12月6日什么星座 | 辛未日五行属什么 | 沉网和浮网有什么区别 | 忤逆是什么意思 | 妍五行属性是什么 |
芡实不能和什么一起吃 | 补办户口本需要什么材料 | 最好的烟是什么牌子 | 银行降息意味着什么 | 鸣字五行属什么 |
玉米不能和什么食物一起吃hcv7jop6ns8r.cn | 脑梗前有什么征兆bysq.com | 小狗感冒症状是什么样的hcv8jop1ns3r.cn | 凭什么我买单hcv8jop5ns2r.cn | 解脲支原体阳性是什么意思hcv7jop9ns4r.cn |
塑料水杯什么材质好hcv7jop6ns4r.cn | 为什么总是拉肚子tiangongnft.com | 甲状腺应该多吃什么hcv8jop5ns3r.cn | 脚热是什么原因引起的huizhijixie.com | 黄芪有什么作用hcv9jop0ns5r.cn |
淋巴结炎挂什么科hcv8jop0ns0r.cn | 胸疼什么原因fenrenren.com | 红斑狼疮是什么病hcv9jop8ns1r.cn | 低密度灶是什么意思hcv8jop3ns4r.cn | 吃什么清理脑血管堵塞hcv9jop4ns6r.cn |
脑震荡后眩晕吃什么药hcv8jop9ns3r.cn | 什么是冰种翡翠hcv9jop3ns5r.cn | 农历六月十七是什么星座sscsqa.com | 鼻子一直流血是什么原因hcv9jop2ns3r.cn | 脑白质脱髓鞘改变是什么意思hcv7jop6ns1r.cn |