pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。
INSERT — 向一个表中插入新行
INSERT INTOtable[ (column[, ...] ) ] { VALUES (expression[, ...] ) | SELECTquery}
table一个已存在表的名称。
columntable中一个列的名称。
expression要赋予column的一个有效表达式或值。
query一个有效的查询。有效参数的进一步描述请参考 SELECT 语句。
INSERT oid 1只插入了一行时返回的消息。 → 是被插入行的行标识符。oid
INSERT 0 #插入了多行时返回的消息。 → 是插入的行数。#
INSERT 允许我们向一个表中插入新行。可以一次插入一行,也可以插入一个查询结果的多个行。目标列表中的列可以按任意顺序列出。对于目标列表中没有出现的每个列,将插入默认值;如果列没有声明的默认值,则假定为 NULL。如果每个列的表达式数据类型不正确,将尝试自动类型强制转换。
要向一个表追加数据,你必须拥有该表上的 insert 权限,并且对 WHERE 子句中指定的任何表拥有 select 权限。
--Insert a single row into table films;
--(in the second example the column date_prod is omitted
--therefore will be stored in it a default value of NULL):
--
INSERT INTO films VALUES
('UA502','Bananas',105,'1971-07-13','Comedy',INTERVAL '82 minute');
INSERT INTO films (code, title, did, date_prod, kind)
VALUES ('T_601', 'Yojimbo', 106, DATE '1961-06-16', 'Drama');
--Insert a single row into table distributors, note that
--only column "name" is specified, to the non specified
--column "did" will be assigned its default value:
--
INSERT INTO distributors (name) VALUES ('British Lion');
--Insert several rows into table films from table tmp:
--
INSERT INTO films
SELECT * FROM tmp;
--Insert into arrays:
--Create an empty 3x3 gameboard for noughts-and-crosses
--(all of these queries create the same board attribute)
--(Refer to the PostgreSQL User's Guide for further
--information about arrays).
INSERT INTO tictactoe (game, board[1:3][1:3])
VALUES (1,'{{"","",""},{},{"",""}}');
INSERT INTO tictactoe (game, board[3][3])
VALUES (2,'{}');
INSERT INTO tictactoe (game, board)
VALUES (3,'{{,,},{,,},{,,}}');
INSERT 语句与 SQL92 完全兼容。query子句特性方面可能存在的限制记录在 SELECT 语句中。
译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。