Postgresql的一些语法

两表关联更新

  • PostgreSQL在两表关联(联合)更新时,跟MySQL是不一样的。要注意关键词set后面的目标列名不能用表名或者表别名来引用,直接使用列名即可,否则会出现语法错误。

错误sql示范:

update user u set u.username = s.student_no from student s where s.user_id = u.id;

正确示范:

update user u set username = s.student_no from student s where s.user_id = u.id;

参考:https://blog.csdn.net/weixin_42659958/article/details/89888679

修改字段类型

和mysql也不一样:

alter table user alter column password type character varying(128);

猜你喜欢

转载自blog.csdn.net/rakish_wind/article/details/110818339