前言
很久没更博客了,markdown语法都快忘了,排版可能丑点,将就着看吧。
年前的时候,公司安排写一个数据清洗,生成一张表,技术层面不复杂,主要就是逻辑上复杂一些,各种update写了1000多行,一共关联10张表。那时候其实公司已经用了postgresql了,老的sqlserver也一直在用,当时想着sqlserver上写一下,后面移植到postgresql就好了。但没想到,这简直是给自己挖了一个大坑,后面逐句调试才成功。
1、update中不可以有inner join等,连接条件要写在where后面 。
update table1 set column = table2.colunm from table2,table3,table4
where table1.id = table2.id and table1.id = table3.id and table1.id = table4.id ...
2、表格中null值必须单独使用is null 判断,例如一个字段中只有1种显示作为标记。
id | name | student |
---|---|---|
1 | 张三 | 1 |
2 | 李四 | |
3 | 王五 | 1 |
4 | 赵六 |
图中表user中student字段,1代表是学生,空代表不是学生,假设此字段为varchar类型。
select * from user where student = '1' # 这是查询所有学生
注意坑来了,在SQLserver中可以使用下面这个
select * from user where student != '1' # SQLserver完美执行
但是在postgresql中必须使用
select * from user where student is null # postgresql这样才可以查得到
虽然就这两个小问题,但是基本上让我把这1000多行重写了一遍。。。