下面是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 *;
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试