• 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)
    
    
  • 相关阅读:
    Linux下增加User及添加sudo权限
    windows下的asp.net core开发及docker下的发布
    Linux下建立虚拟内存
    Github访问慢解决办法
    Uva 10061
    SYOJ 1001. Alphacode
    SRM144DIV1 Lottery
    SRM609 DIV2 950
    mysql 半同步
    mysql root用户不知到密码的情况下修改密码
  • 原文地址:https://www.cnblogs.com/yldf/p/11899982.html
Copyright © 2020-2023  润新知