1.Base基础/3.Icon图标/操作/search备份
1.Base基础/3.Icon图标/操作/search备份
EN
文档
AntDB简介
快速入门
用户手册
数据安全
系统架构
最佳实践
参考指南
  • 文档首页 /
  • 用户手册 /
  • 增删改查 /
  • 表中插入数据

表中插入数据

更新时间:2024-04-13 04:57:48

表创建完成后,表中没有数据,可以使用insert语句向表中插入一行或多行数据。

通过\h insert 可以得到insert命令的帮助信息:

antdb=# \h insert
Command:     INSERT
Description: create new rows in a table
Syntax:
[ WITH [ RECURSIVE ] with_query [, ...] ]
INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ]
    [ OVERRIDING { SYSTEM | USER} VALUE ]
    { 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 [, ...] ) = [ ROW ] ( { expression | DEFAULT } [, ...] ) |
                    ( column_name [, ...] ) = ( sub-SELECT )
                  } [, ...]
              [ WHERE condition ]

常用的insert语法包括:

  • insert into table vaules (); 每次一行数据
  • insert into table vaules (),(),(),()....; 每次多行数据
  • insert into table select * from table2; 从其他表导入数据
  • insert into t_count values (1,'a') ON CONFLICT (id) do update set name='b' ; insert的同时处理冲突
问题反馈