如何在 postgresql 中为空单元格设置 IsNullOrEmpty 条件?
How Can I Make the Condition For IsNullOrEmpty for Empty cell in postgresql?
我的成绩是 A table
id | Marks
----------------+----------
1 |
2 | 33
for record in (select Marks from grades)
loop
marks=rec.Marks;
if(marks is null) then
marks=0;
end if;
end loop;
My Problem is in if condition how to write the condition for marks is
null, marks is a integer type
要更改值,请使用 update 语句:
update grades
set marks = 0
where marks is null;
要插入数据,请使用带有合并的 insert
语句:
insert into temp_table (col1, marks)
select col1, coalesce(marks, 0)
from grades;
如果您想在检索时更改此设置,您还可以使用 CASE 或 COALESCE
SELECT col1, COALESCE(marks, 0) as MARKS from grades
或
SELECT col1, CASE WHEN marks IS NULL THEN 0 ELSE marks END AS marks
FROM grades
我的成绩是 A table
id | Marks
----------------+----------
1 |
2 | 33
for record in (select Marks from grades)
loop
marks=rec.Marks;
if(marks is null) then
marks=0;
end if;
end loop;
My Problem is in if condition how to write the condition for marks is null, marks is a integer type
要更改值,请使用 update 语句:
update grades
set marks = 0
where marks is null;
要插入数据,请使用带有合并的 insert
语句:
insert into temp_table (col1, marks)
select col1, coalesce(marks, 0)
from grades;
如果您想在检索时更改此设置,您还可以使用 CASE 或 COALESCE
SELECT col1, COALESCE(marks, 0) as MARKS from grades
或
SELECT col1, CASE WHEN marks IS NULL THEN 0 ELSE marks END AS marks
FROM grades