postgresql 判断是空的_PostgreSQL对空值处理nullif函数

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


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部