• 技术文章 >数据库 >PostgreSQL

    postgresql和mysql语句区别

    silencementsilencement2020-01-06 11:17:44原创4040

    下面是MySQL和postgresql的语句区别,有需要的可以借鉴学习

    1 UPDATE

    1.1更新并返回

    MySQL:

    SELECT temp_lo,temp_hi,prcp FROM UPDATE wheather SET temp_lo =

    temp_lo+1,temp_hi = temp_lo+15 WHERE city = ‘San Francisco’;

    PostgreSQL:

    UPDATE wheather SET temp_lo = temp_lo+1,temp_hi = temp_lo+15 WHERE city =

    ‘San Francisco’ RETURNING temp_lo,temp_hi;

    1.2 表关联多字段更新

    MySQL:无

    PostgreSQL:

    UPDATE accounts SET (Contact_last_name,cONtact_first_name) = (SELECT

    Last_name,first_name FROM salesmen WHERE salesmen.id = accounts.sales_id);

    2 INSERT

    2.1 插入并返回

    MySQL:无

    PostgreSQL:

    INSERT INTO distributors (did,dname) VALUES (DEFAULT,’XYZ’) RETURNING did;

    2.2 插入冲突则更新

    MySQL:

    INSERT INTO distributors (did,dname) VALUES (5,’Gizmo’),(6,’INc’) ON
    DUPLICATE KEY UPDATE dname = EXCLUDED.dname;

    PostgreSQL:

    INSERT INTO distributors (did,dname) VALUES (5,’Gizmo’),(6,’INc’) ON
    CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname;

    推荐学习《python教程

    2.3 插入冲突则什么都不做

    MySQL:

    INSERT IGNORE INTO distributors (did,dname) VALUES (9,’Design’);

    PostgreSQL:

    INSERT INTO distributors (did,dname) VALUES (9,’Design’) ON CONFLICT ON
    CONSTRAINT distributors_pkey DO NOTHING;

    3 SELECT

    4 DELETE

    4.1 删除并返回删除的内容

    MySQL:无

    PostgreSQL:

    DELETE FROM tasks WHERE status = ‘DONE’ RETURNING *;
    专题推荐:postgresql
    上一篇:postgresql国内哪些公司在用 下一篇:postgresql应用场景是什么

    相关文章推荐

    • postgresql如何备份• postgresql怎么创建数据表

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网