PostgreSQL小技巧
无表查询
select * from (values(1,'刘德华'),(2,'周星驰'),(3,'黎明')) as t(id,name);
|
id
integer
|
name
text
|
|---|---|
| 1 | 刘德华 |
| 2 | 周星驰 |
| 3 | 黎明 |
更高效的清空表里面所有的数据
当我们想要清空表里面所有的数据的时候,应该使用 truncate 表,而不是 delete 所有数据。 清除表:truncate table tablename; 删除表所有数据:delete from tablename;
当数据为null时转换为其他值
使用coalesce函数:select coalesce(null, 1);