
postgresql 判断是空的
nullif(var1,var2)
如果var1和var2相等则返回null,如果不相等则返回var1
select nullif(1,null); 结果:1
select nullif(null,1); 结果:null
select nullif(1,1); 结果:null
select nullif(1,0); 结果:1
create table posts(
id serial primary key,
title varchar(255) not null,
excerpt varchar(255),
body text,
create_tiem timestamp default current_timestamp,
update_time timestamp
);
insert into posts(title,excerpt,body) values
(\'test post 1\',\'test post excerpt 1\',\'test post body 1\'),
(\'test post 2\',\'\',\'test post body 2\'),
(\'test post 3\', null ,\'test post body 3\');
案例1:
select id,title ,excerpt from posts;
结果:由结果得知excerpt有空值null
id title excerpt
1 test post 1 test post excerpt 1
2