小编给大家分享一下postgresql和mysql语句有什么区别,相信大部分人都还不怎么了解,因此分享这边文章给大家学习,希望大家阅读完这篇文章后大所收获,下面让我们一起去学习方法吧!
下面是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’;
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;
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 *;