Window function IGNORE NULLS workaround for PostgreSQL
LAG() doesn't repeat the last non null value.

Quoted from docs


  returns value evaluated at the row that is offset rows before the current row within the partition; if there is no such row, instead return default (which must be of the same type as value)


But you can set a partition depending on one column value and then use firts_value() function.




create table tbl (id int, a int, b int, c int);



✓






insert into tbl values
(1, 12, 4, 3),
(2, 10, 10, 5),
(3, 6, 12, 23),
(4, 6, null, 10),
(5, 7, null, 4),
(6, 1, 8, 10),
(7, 4, null, 3);



7 rows affected






select id, a, first_value(b) over (partition by grp) as b, c
from (
      select id, a, b, c, 
             sum(case when b is not null then 1 end) over (order by id) as grp
      from   tbl
     ) t



id |  a |  b |  c
-: | -: | -: | -:
 1 | 12 |  4 |  3
 2 | 10 | 10 |  5
 3 |  6 | 12 | 23
 4 |  6 | 12 | 10
 5 |  7 | 12 |  4
 6 |  1 |  8 | 10
 7 |  4 |  8 |  3



db&lt;>fiddle here