zoukankan      html  css  js  c++  java
  • postgres DML操作并返回结果

    insert操作并返回结果

    imos=#  CREATE TABLE person (
    imos(#       id   SERIAL,
    imos(#       name TEXT
    imos(#    );
    CREATE TABLE
    imos=#
    imos=#
    imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id;
     id
    ----
      1
    (1 row)
    
    INSERT 0 1
    imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id;
     id
    ----
      2
    (1 row)
    
    INSERT 0 1
    imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING *;
     id |     name
    ----+---------------
      3 | Blaise Pascal
    (1 row)
    
    INSERT 0 1
    imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING null;
     ?column?
    ----------
    
    (1 row)
    
    INSERT 0 1
    imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') ;
    INSERT 0 1
    
    

    delete 操作并返回结果

    imos=# select * from person;
     id |     name
    ----+---------------
      1 | Blaise Pascal
      2 | Blaise Pascal
      3 | Blaise Pascal
      4 | Blaise Pascal
      5 | Blaise Pascal
    (5 rows)
    
    imos=# delete from person where id=1;
    DELETE 1
    imos=# select * from person;
     id |     name
    ----+---------------
      2 | Blaise Pascal
      3 | Blaise Pascal
      4 | Blaise Pascal
      5 | Blaise Pascal
    (4 rows)
    
    imos=# delete from person where id=2 returning *;
     id |     name
    ----+---------------
      2 | Blaise Pascal
    (1 row)
    
    DELETE 1
    imos=# delete from person where id=3 returning null;
     ?column?
    ----------
    
    (1 row)
    
    DELETE 1
    imos=# select * from person;
     id |     name
    ----+---------------
      4 | Blaise Pascal
      5 | Blaise Pascal
    (2 rows)
    
    imos=# delete from person where id=4 returning name;
         name
    ---------------
     Blaise Pascal
    (1 row)
    
    DELETE 1
    imos=# delete from person where id=5 returning id;
     id
    ----
      5
    (1 row)
    
    DELETE 1
    imos=# select * from person;
     id | name
    ----+------
    (0 rows)
    
    

    update操作并返回结果

    imos=# select * from person;
     id | name
    ----+------
    (0 rows)
    
    imos=#
    imos=#
    imos=#
    imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') ;
    INSERT 0 1
    imos=# select * from person;
     id |     name
    ----+---------------
      6 | Blaise Pascal
    (1 row)
    
    imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal32') ;
    INSERT 0 1
    imos=# select * from person;
     id |      name
    ----+-----------------
      6 | Blaise Pascal
      7 | Blaise Pascal32
    (2 rows)
    
    imos=# update person set name='test' where id=6 returning *;
     id | name
    ----+------
      6 | test
    (1 row)
    
    UPDATE 1
    imos=# select * from person;
     id |      name
    ----+-----------------
      7 | Blaise Pascal32
      6 | test
    (2 rows)
    
    imos=# update person set name='test' where id=7 returning name;
     name
    ------
     test
    (1 row)
    
    UPDATE 1
    imos=# select * from person;
     id | name
    ----+------
      6 | test
      7 | test
    (2 rows)
    
    
  • 相关阅读:
    oracle中去掉文本中的换行符、回车符、制表符
    oracle中的exists和not exists和in用法详解
    将异常(getStackTrace)转化成String
    树的深度优先遍历和广度优先遍历的原理和java实现代码
    extjs4.0 treepanel节点的选中、展开! 数据的重新加载
    揭秘对象
    JVM由浅入深
    语法糖
    Java的技术体系结构
    菜鸟笔记 -- Chapter 09 常见类和接口
  • 原文地址:https://www.cnblogs.com/yldf/p/11899982.html
Copyright © 2011-2022 走看看