insert 插入

insert


[ 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 ]

test=> insert into ask(id,publisherID,reward,cost,rangee,typee,label,content,image,createTime,zan,school,college) values
test-> (1,1,4,10,'school','急问','学习','这道题怎么做','{"/icon/default.ico"}',now(),1,'广州大学',null),
test-> (2,2,10,10,'school','急问','实习','xxx公司怎样','{"/icon/default.ico"}',now(),2,'广州大学',null),
test-> (3,3,100,10,'college','急问','美食','xxx好不好吃','{"/icon/default.ico"}',now(),3,'广州大学','计算机科学与教育软件学院'),
test-> (4,4,200,10,'college','急问','其它','xxx怎么去','{"/icon/default.ico"}',now(),4,'广州大学','计算机科学与教育软件学院'),
test-> (5,3,100,10,'college','急问','美食','xxx好不好吃','{"/icon/default.ico"}',now(),5,'广州大学','人文学院'),
test-> (6,4,200,10,'college','急问','其它','xxx怎么去','{"/icon/default.ico"}',now(),6,'广州大学','人文学院') on conflict do nothing;
INSERT 0 4

这里的on conflict是对于每一行来说的



posted @ 2017-07-13 11:52  cdongyang  阅读(1144)  评论(0编辑  收藏  举报