什么茶可以减肥消脂| 32周做什么检查| 煲什么汤含蛋白质高| 无限极是干什么的| psp是什么意思| 走路带风是什么意思| 7月13日是什么节日| 低头什么节| 刚感染艾滋病什么症状| package什么意思| 1994年属狗的是什么命| 四月初八是什么节日| 抗病毒什么药效果好| 什么叫湿气| 冒失是什么意思| 牛巴是什么| 蛇的天敌是什么| 梦见打碎碗是什么预兆| 空腹喝可乐有什么危害| 道字五行属什么| 半边脸发麻是什么原因| 血压计什么牌子好| 伦字五行属什么| 一般什么人会有美人尖| bj什么意思| 为什么一吃辣的就拉肚子| 藜芦是什么东西| 喝咖啡胃疼是什么原因| 两腿抽筋是什么原因| 为什么有的人特别招蚊子| 牛仔是什么面料| 脑电图能检查出什么疾病| ao是什么| 血糖高吃什么可以降下来| 砖红色是什么颜色| 冰鱼是什么鱼| 墓志铭什么意思| 空调外机风扇不转是什么原因| 清什么什么月| 89岁属什么生肖| 梦见家里好多蛇是什么预兆| 口炎读什么| 碘伏遇到什么会变白| 缘是什么生肖| p5是什么意思| 补钙最好的食物是什么| 胸推是什么意思| 孙悟空最后成了什么佛| 九眼天珠适合什么人戴| 无回声结节是什么意思| 织女是什么意思| 金瓶梅是什么| 四时是什么意思| 喝藏红花有什么好处| 怀才不遇是什么意思| 心服口服是什么意思| 十一月是什么星座| 梦见骆驼是什么意思| 软开是什么| 黑胡椒和白胡椒有什么区别| 尿毒症是什么症状| 背后长痘是什么原因| 10.19什么星座| 尽虚空遍法界什么意思| 龙骨是什么骨头| 一什么尺子| 尿隐血十1是什么意思| 豆腐吃多了有什么坏处| 三体是什么| 80年属什么生肖| 西地那非是什么| 结石吃什么药好| 什么样的人死后还会出现| 印度讲什么语言| 结婚30年是什么婚姻| 口腔溃疡是什么样子| 吃什么食物补钙| 匿名是什么意思| 9月是什么季节| 咳嗽黄痰吃什么药| 人头什么动| 舌头热灼是什么原因| 为什么时间越来越快| 肚脐眼下面是什么部位| 两只小船儿孤孤零零是什么歌| 属猴的和什么属相最配| 月经提前十几天是什么原因| 为什么挠脚心会痒| 阴茎不够硬吃什么药| verde是什么颜色| 自然生化流产是什么意思| 胃窦粘膜慢性炎是什么病| 6月9日什么星座| tips是什么意思| 脸水肿是什么原因| 偏财代表什么| 支那人是什么意思| 未加一笔是什么字| 吩可以组什么词| 梦见佛像是什么预兆| 火热是什么意思| 眼疖子用什么药| 女朋友过生日送什么最好| 数脉是什么意思| point是什么意思| 安道尔微信暗示什么| 颈椎病有些什么症状| 阳瘘的最佳治疗方法是什么| 芒果有什么营养价值| 运字是什么结构| 鸡胸肉炒什么菜好吃| 喝太多水对身体有什么影响| 正常人突然抽搐是什么原因| 精益求精下一句是什么| 什么惊什么怪| 单核细胞百分比偏高什么原因| robot什么意思| 智五行属性是什么| 耳石症挂什么科| 指征是什么意思| 头发不长是什么原因| lh是什么意思啊| 超声波检查是什么检查| 刮宫后能吃什么水果| 睾丸皮痒用什么药| 劝退是什么意思| 雪梨百合炖冰糖有什么功效| 硫磺是什么| 什么情况下需要安装心脏起搏器| bag是什么意思| 舅舅的老婆叫什么| 珎是什么意思| 什么情况| 2月7号是什么星座| 男人精子少吃什么药| 失温是什么意思| 喝红枣水有什么好处和坏处| 什么的形状| 蜂蜜什么时间喝最好| 啤酒加生鸡蛋一起喝有什么效果| 接触性皮炎用什么药| 抱怨是什么意思| 菊花什么季节开| 张良和刘邦是什么关系| 身披枷锁是什么生肖| 胺试验阳性是什么意思| 尿血什么原因| 为什么小腹隐隐作痛| 办健康证在什么地方办| 关东煮是什么| 检查胸部应该挂什么科| 长脸男生适合什么发型| 12月26日是什么星座| 序曲是什么意思| 示数是什么意思| 今天的日子适合做什么| 呈味核苷酸二钠是什么| 政委是什么级别| 用一什么就什么造句| 寓教于乐什么意思| 饶舌是什么意思| 什么力竭| 令堂是什么意思| 血氧低会有什么危害| 儿童看包皮挂什么科| 吃什么长头发快| 晚饭后散步有什么好处| 亥时右眼跳是什么预兆| 小鸟站在高压线上为什么不会触电| b2驾照能开什么车| 八带是什么| 属狗的和什么属相最配| 角化型脚气用什么药膏| 乙肝两对半25阳性是什么意思| 田螺姑娘是什么意思| 月经提前十几天是什么原因| 口苦是什么原因造成的| 庖丁是什么意思| 干白是什么酒| 动一下就出汗是什么原因| 毒龙什么意思| 井代表什么生肖| 堞是什么意思| 生粉是什么粉| 指甲花学名叫什么| 12月18日什么星座| 什么口| 为什么会晨勃| 夏天喝什么饮料好| 高血压会引起什么并发症| 茯茶是什么茶| 检查骨密度挂什么科| 张杰属什么生肖| 统招生是什么意思| 双角子宫是什么意思| stomach什么意思| 晚饭吃什么减肥| 梦见很多狗是什么意思| 什么是部首| 沉香木是什么| 7月4号什么星座| 换肾是什么病| 流产有什么症状| 六小龄童的真名叫什么| 乳房钙化灶是什么意思| s是什么m是什么| 七一年属什么生肖| 吃什么排铜最快| 繁字五行属什么| 梦见鱼是什么预兆| 房颤吃什么药好| 经期是什么意思| 中签是什么意思| 做核磁共振挂什么科| 吃什么水果对肺好| 鼻炎咳嗽吃什么药| 懿读什么| 积液是什么东西| 梦见自己会飞是什么意思| 橙色五行属什么| 既视感什么意思| 藿香正气水是什么| chick是什么意思| 老鼠疮是什么病| 吃什么补红细胞最快| guess什么牌子| 恳谈会是什么意思| 右手掌心有痣代表什么| 参军意愿选什么比较好| 7月7号是什么星座| 胎位rsa是什么意思| 后背发冷发凉属于什么症状| 异位性皮炎是什么意思| 天外飞仙是什么意思| 指甲变空是什么原因| 猴年马月什么意思| 上传下达什么意思| 日晡潮热是什么意思| 淋病有什么症状| 胎盘1级什么意思| 出生医学证明有什么用| 一进去就射是什么原因| 养老保险什么时候开始交| 拔罐出水是什么原因| 感冒没胃口吃什么好| 基因是什么| 腱鞘炎是什么原因| 孕激素低吃什么补得快| 兔子的天敌是什么动物| 早孕是什么意思| 绿豆芽炒什么好吃| 4月24号是什么星座| 66年属什么| 男属鼠的和什么属相最配| 补气血什么季节补最好| ara是什么| 倾注是什么意思| 3月23是什么星座| 瓠子和什么相克| 为什么下巴经常长痘痘| 谷丙转氨酶是检查什么| pony什么意思| surprise是什么意思| 刘备属相是什么生肖| 百度
Supported Versions: Current (17) / 16 / 15 / 14 / 13
Development Versions: 18 / devel
Unsupported versions: 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

【网信事业新成就】科大讯飞:让世界聆听安徽的声音

Name

INSERT -- create new rows in a table

Synopsis

百度 印刷技术是中国对世界文明的一大重要贡献,它不仅在中国古代发挥着传承文化的作用,同时也影响着世界历史的进程。
[ WITH [ RECURSIVE ] with_query [, ...] ]
INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ]
    { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query }
    [ ON CONFLICT [ conflict_target ] conflict_action ]
    [ RETURNING * | output_expression [ [ AS ] output_name ] [, ...] ]

where conflict_target can be one of:

    ( { index_column_name | ( index_expression ) } [ COLLATE collation ] [ opclass ] [, ...] ) [ WHERE index_predicate ]
    ON CONSTRAINT constraint_name

and conflict_action is one of:

    DO NOTHING
    DO UPDATE SET { column_name = { expression | DEFAULT } |
                    ( column_name [, ...] ) = ( { expression | DEFAULT } [, ...] ) |
                    ( column_name [, ...] ) = ( sub-SELECT )
                  } [, ...]
              [ WHERE condition ]

Description

INSERT inserts new rows into a table. One can insert one or more rows specified by value expressions, or zero or more rows resulting from a query.

The target column names can 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.

ON CONFLICT can be used to specify an alternative action to raising a unique constraint or exclusion constraint violation error. (See ON CONFLICT Clause below.)

The optional RETURNING clause causes INSERT to compute and return value(s) based on each row actually inserted (or updated, if an ON CONFLICT DO UPDATE clause was used). This is primarily useful for obtaining values that were supplied by defaults, such as a serial sequence number. However, any expression using the table's columns is allowed. The syntax of the RETURNING list is identical to that of the output list of SELECT. Only rows that were successfully inserted or updated will be returned. For example, if a row was locked but not updated because an ON CONFLICT DO UPDATE ... WHERE clause condition was not satisfied, the row will not be returned.

You must have INSERT privilege on a table in order to insert into it. If ON CONFLICT DO UPDATE is present, UPDATE privilege on the table is also required.

If a column list is specified, you only need INSERT privilege on the listed columns. Similarly, when ON CONFLICT DO UPDATE is specified, you only need UPDATE privilege on the column(s) that are listed to be updated. However, ON CONFLICT DO UPDATE also requires SELECT privilege on any column whose values are read in the ON CONFLICT DO UPDATE expressions or condition.

Use of the RETURNING clause requires SELECT privilege on all columns mentioned in RETURNING. If you use the query clause to insert rows from a query, you of course need to have SELECT privilege on any table or column used in the query.

Parameters

Inserting

This section covers parameters that may be used when only inserting new rows. Parameters exclusively used with the ON CONFLICT clause are described separately.

with_query

The WITH clause allows you to specify one or more subqueries that can be referenced by name in the INSERT query. See Section 7.8 and SELECT for details.

It is possible for the query (SELECT statement) to also contain a WITH clause. In such a case both sets of with_query can be referenced within the query, but the second one takes precedence since it is more closely nested.

table_name

The name (optionally schema-qualified) of an existing table.

alias

A substitute name for table_name. When an alias is provided, it completely hides the actual name of the table. This is particularly useful when ON CONFLICT DO UPDATE targets a table named excluded, since that's also the name of the special table representing rows proposed for insertion.

column_name

The name of a column in the table named by table_name. 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.) When referencing a column with ON CONFLICT DO UPDATE, do not include the table's name in the specification of a target column. For example, INSERT INTO table_name ... ON CONFLICT DO UPDATE SET table_name.col = 1 is invalid (this follows the general behavior for UPDATE).

DEFAULT VALUES

All columns will be filled with their default values.

expression

An expression or value to assign to the corresponding column.

DEFAULT

The corresponding column will be filled with its default value.

query

A query (SELECT statement) that supplies the rows to be inserted. Refer to the SELECT statement for a description of the syntax.

output_expression

An expression to be computed and returned by the INSERT command after each row is inserted or updated. The expression can use any column names of the table named by table_name. Write * to return all columns of the inserted or updated row(s).

output_name

A name to use for a returned column.

ON CONFLICT Clause

The optional ON CONFLICT clause specifies an alternative action to raising a unique violation or exclusion constraint violation error. For each individual row proposed for insertion, either the insertion proceeds, or, if an arbiter constraint or index specified by conflict_target is violated, the alternative conflict_action is taken. ON CONFLICT DO NOTHING simply avoids inserting a row as its alternative action. ON CONFLICT DO UPDATE updates the existing row that conflicts with the row proposed for insertion as its alternative action.

conflict_target can perform unique index inference. When performing inference, it consists of one or more index_column_name columns and/or index_expression expressions, and an optional index_predicate. All table_name unique indexes that, without regard to order, contain exactly the conflict_target-specified columns/expressions are inferred (chosen) as arbiter indexes. If an index_predicate is specified, it must, as a further requirement for inference, satisfy arbiter indexes. Note that this means a non-partial unique index (a unique index without a predicate) will be inferred (and thus used by ON CONFLICT) if such an index satisfying every other criteria is available. If an attempt at inference is unsuccessful, an error is raised.

ON CONFLICT DO UPDATE guarantees an atomic INSERT or UPDATE outcome; provided there is no independent error, one of those two outcomes is guaranteed, even under high concurrency. This is also known as UPSERT"UPDATE or INSERT".

conflict_target

Specifies which conflicts ON CONFLICT takes the alternative action on by choosing arbiter indexes. Either performs unique index inference, or names a constraint explicitly. For ON CONFLICT DO NOTHING, it is optional to specify a conflict_target; when omitted, conflicts with all usable constraints (and unique indexes) are handled. For ON CONFLICT DO UPDATE, a conflict_target must be provided.

conflict_action

conflict_action specifies an alternative ON CONFLICT action. It can be either DO NOTHING, or a DO UPDATE clause specifying the exact details of the UPDATE action to be performed in case of a conflict. The SET and WHERE clauses in ON CONFLICT DO UPDATE have access to the existing row using the table's name (or an alias), and to rows proposed for insertion using the special excluded table. SELECT privilege is required on any column in the target table where corresponding excluded columns are read.

Note that the effects of all per-row BEFORE INSERT triggers are reflected in excluded values, since those effects may have contributed to the row being excluded from insertion.

index_column_name

The name of a table_name column. Used to infer arbiter indexes. Follows CREATE INDEX format. SELECT privilege on index_column_name is required.

index_expression

Similar to index_column_name, but used to infer expressions on table_name columns appearing within index definitions (not simple columns). Follows CREATE INDEX format. SELECT privilege on any column appearing within index_expression is required.

collation

When specified, mandates that corresponding index_column_name or index_expression use a particular collation in order to be matched during inference. Typically this is omitted, as collations usually do not affect whether or not a constraint violation occurs. Follows CREATE INDEX format.

opclass

When specified, mandates that corresponding index_column_name or index_expression use particular operator class in order to be matched during inference. Typically this is omitted, as the equality semantics are often equivalent across a type's operator classes anyway, or because it's sufficient to trust that the defined unique indexes have the pertinent definition of equality. Follows CREATE INDEX format.

index_predicate

Used to allow inference of partial unique indexes. Any indexes that satisfy the predicate (which need not actually be partial indexes) can be inferred. Follows CREATE INDEX format. SELECT privilege on any column appearing within index_predicate is required.

constraint_name

Explicitly specifies an arbiter constraint by name, rather than inferring a constraint or index.

condition

An expression that returns a value of type boolean. Only rows for which this expression returns true will be updated, although all rows will be locked when the ON CONFLICT DO UPDATE action is taken. Note that condition is evaluated last, after a conflict has been identified as a candidate to update.

Note that exclusion constraints are not supported as arbiters with ON CONFLICT DO UPDATE. In all cases, only NOT DEFERRABLE constraints and unique indexes are supported as arbiters.

INSERT with an ON CONFLICT DO UPDATE clause is a "deterministic" statement. This means that the command will not be allowed to affect any single existing row more than once; a cardinality violation error will be raised when this situation arises. Rows proposed for insertion should not duplicate each other in terms of attributes constrained by an arbiter index or constraint.

Tip: It is often preferable to use unique index inference rather than naming a constraint directly using ON CONFLICT ON CONSTRAINT constraint_name. Inference will continue to work correctly when the underlying index is replaced by another more or less equivalent index in an overlapping way, for example when using CREATE UNIQUE INDEX ... CONCURRENTLY before dropping the index being replaced.

Outputs

On successful completion, an INSERT command returns a command tag of the form

INSERT oid count

The count is the number of rows inserted or updated. If count is exactly one, and the target table has OIDs, then oid is the OID assigned to the inserted row. The single row must have been inserted rather than updated. Otherwise oid is zero.

If the INSERT command contains a RETURNING clause, the result will be similar to that of a SELECT statement containing the columns and values defined in the RETURNING list, computed over the row(s) inserted or updated by the command.

Examples

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;

To insert multiple rows using the multirow VALUES syntax:

INSERT INTO films (code, title, did, date_prod, kind) VALUES
    ('B6717', 'Tampopo', 110, '2025-08-08', 'Comedy'),
    ('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy');

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
INSERT INTO tictactoe (game, board[1:3][1:3])
    VALUES (1, '{{" "," "," "},{" "," "," "},{" "," "," "}}');
-- The subscripts in the above example aren't really needed
INSERT INTO tictactoe (game, board)
    VALUES (2, '{{X," "," "},{" ",O," "},{" ",X," "}}');

Insert a single row into table distributors, returning the sequence number generated by the DEFAULT clause:

INSERT INTO distributors (did, dname) VALUES (DEFAULT, 'XYZ Widgets')
   RETURNING did;

Increment the sales count of the salesperson who manages the account for Acme Corporation, and record the whole updated row along with current time in a log table:

WITH upd AS (
  UPDATE employees SET sales_count = sales_count + 1 WHERE id =
    (SELECT sales_person FROM accounts WHERE name = 'Acme Corporation')
    RETURNING *
)
INSERT INTO employees_log SELECT *, current_timestamp FROM upd;

Insert or update new distributors as appropriate. Assumes a unique index has been defined that constrains values appearing in the did column. Note that the special excluded table is used to reference values originally proposed for insertion:

INSERT INTO distributors (did, dname)
    VALUES (5, 'Gizmo Transglobal'), (6, 'Associated Computing, Inc')
    ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname;

Insert a distributor, or do nothing for rows proposed for insertion when an existing, excluded row (a row with a matching constrained column or columns after before row insert triggers fire) exists. Example assumes a unique index has been defined that constrains values appearing in the did column:

INSERT INTO distributors (did, dname) VALUES (7, 'Redline GmbH')
    ON CONFLICT (did) DO NOTHING;

Insert or update new distributors as appropriate. Example assumes a unique index has been defined that constrains values appearing in the did column. WHERE clause is used to limit the rows actually updated (any existing row not updated will still be locked, though):

-- Don't update existing distributors based in a certain ZIP code
INSERT INTO distributors AS d (did, dname) VALUES (8, 'Anvil Distribution')
    ON CONFLICT (did) DO UPDATE
    SET dname = EXCLUDED.dname || ' (formerly ' || d.dname || ')'
    WHERE d.zipcode <> '21201';

-- Name a constraint directly in the statement (uses associated
-- index to arbitrate taking the DO NOTHING action)
INSERT INTO distributors (did, dname) VALUES (9, 'Antwerp Design')
    ON CONFLICT ON CONSTRAINT distributors_pkey DO NOTHING;

Insert new distributor if possible; otherwise DO NOTHING. Example assumes a unique index has been defined that constrains values appearing in the did column on a subset of rows where the is_active Boolean column evaluates to true:

-- This statement could infer a partial unique index on "did"
-- with a predicate of "WHERE is_active", but it could also
-- just use a regular unique constraint on "did"
INSERT INTO distributors (did, dname) VALUES (10, 'Conrad International')
    ON CONFLICT (did) WHERE is_active DO NOTHING;

Compatibility

INSERT conforms to the SQL standard, except that the RETURNING clause is a PostgreSQL extension, as is the ability to use WITH with INSERT, and the ability to specify an alternative action with ON CONFLICT. Also, 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.

tr是什么 什么是蚕豆病 吃什么水果降火最快 昀是什么意思 米线是什么材料做的
外阴又疼又痒用什么药 完谷不化吃什么中成药 人造石是什么材料做的 眉毛上长痣代表什么 静是什么意思
扁桃体割了对身体有什么影响 满满是什么意思 兰州有什么好吃的 黄芪搭配什么不上火 血糖高适合吃什么
tct检查什么项目 鲤鱼为什么很少人吃 腹泻用什么药 失眠为什么 血糖高吃什么药好
奥氮平片治疗什么病qingzhougame.com 优思悦是什么药beikeqingting.com 算五行缺什么免费测试hcv9jop4ns5r.cn 火华读什么hcv9jop4ns6r.cn perrier是什么水adwl56.com
天上九头鸟地上湖北佬是什么意思hcv9jop1ns4r.cn 生物电是什么qingzhougame.com 宫腔镜是什么检查hcv8jop9ns8r.cn 皇太后是皇上的什么人hcv9jop7ns5r.cn 昆仑雪菊有什么功效sanhestory.com
生蛇是什么原因引起的hcv8jop0ns6r.cn 艺不压身是什么意思wmyky.com 梦到跟人吵架是什么意思hcv8jop5ns8r.cn 喝水不排尿是什么原因hcv7jop9ns2r.cn 豆瓣酱可以做什么菜hcv7jop4ns6r.cn
拿什么让你幸福hcv8jop2ns4r.cn 石钟乳是什么hcv7jop6ns0r.cn 手绘是什么意思hcv8jop2ns4r.cn 新的五行属性是什么hcv9jop3ns7r.cn 穷兵黩武是什么意思hcv9jop3ns1r.cn
百度