第二章 SQL命令参考-INSERT

INSERT

Creates new rows in a table.

概要

 

 

INSERTINTO table [( column [, ...] )]

{DEFAULTVALUES | VALUES ( {expression | DEFAULT} [, ...] )

[,...] | query}

 

描述

INSERT将新行插入到表中。 可以插入由值表达式指定的一行或多行,或者由查询产生的零行或多行。

目标列名称可能以任何顺序列出。 如果没有列名列表,默认是表的列的声明顺序。 由VALUES子句或查询提供的值与从左到右的显式或隐式列列表相关联。

不存在于显式或隐式列列表中的每一列都将使用默认值(其声明的默认值)填充,如果没有默认值则为null。

如果任何列的表达式不是正确的数据类型,将尝试进行自动类型转换。

您必须在表上具有INSERT权限才能插入表中。

parameter

table

现有表的名称(可选模式限定)。

column

表中的列的名称。 如果需要,可以使用子字段名称或数组下标对列名进行限定。 (仅插入复合列的某些字段将使其他字段为空。)

DEFAULT VALUES

所有列将填充其默认值。

expression

要分配给相应列的表达式或值。

DEFAULT

相应的列将被填充其默认值。

query

提供要插入的行的查询(SELECT语句)。 有关语法的描述,请参阅SELECT语句。

Notes

要将数据插入到分区表中,请指定根分区表,使用CREATE TABLE命令创建表。 您还可以在INSERT命令中指定分区表的叶子表。 如果数据对指定的叶子表不起作用,则返回错误。 不支持在INSERT命令中指定不是叶子表的子表。 不支持在分区表的任何子表上执行其他DML命令(如UPDATE和DELETE)。 这些命令必须在根分区表上执行,这是使用CREATE TABLE命令创建的表。

对于附加优化表,Greenplum数据库最多可以将127个并发的INSERT事务分配到单个附加优化表中。

 

示例

Insert a singlerow into table films:

INSERTINTO films VALUES ('UA502', 'Bananas', 105,

'1971-07-13','Comedy', '82 minutes');

In this example,the length column is omitted and thereforeit will have the default value:

INSERTINTO films (code, title, did, date_prod, kind) VALUES

('T_601','YoJimbo', 106, '1961-06-16', 'Drama');

This example usesthe DEFAULT clause for the date_prod column rather than specifying a value:

INSERTINTO films VALUES ('UA502', 'Bananas', 105, DEFAULT,

'Comedy','82 minutes');

 

To insert a rowconsisting entirely of default values:

 

INSERTINTO films DEFAULT VALUES;

To insertmultiple rows using the multirow VALUESsyntax:

INSERTINTO films (code, title, did, date_prod, kind) VALUES

('B6717','Tampopo', 110, '1985-02-10', 'Comedy'),

('HG120','The Dinner Game', 140, DEFAULT, 'Comedy');

This example inserts some rows into table films from a table tmp_films with the samecolumn layout as

films:

INSERTINTO films SELECT * FROM tmp_films WHERE date_prod <

'2004-05-07';

 

 

兼容性

insert conforms to the SQL standard. The case inwhich a column name list is omitted, but not all the columns are filled fromthe values clause orquery, is disallowed by the standard.

Possiblelimitations of the query clause are documented under select.

相关参考

COPY, SELECT, CREATE EXTERNAL TABLE

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值