Use left hand column for null values

Поиск
Список
Период
Сортировка
От
Тема Use left hand column for null values
Дата
Msg-id 006801d3913c$a7b7c420$f7274c60$@gmail.com
обсуждение исходный текст
Ответы Re: Use left hand column for null values  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general

I’m trying to fill up columns containing NULL with the most recent NOT NULL value from left to right.

Example:

Select 2, 1, null, null, 3

Should be converted into

2, 1, 1, 1, 3

 

The following query works but I wonder if there is an easier way for tables with 50 or more columns:

 

with a (c1, c2, c3, c4, c5) as (

values(2, 1, null::int, null::int, 3)

)

select

c1,

coalesce (c2, c1) as c2,

coalesce (c3, c2, c1) as c3,

coalesce (c4, c3, c2, c1) as c4,

coalesce (c5, c4, c3, c2, c1) as c5

from a

 

Thanks

Klaus

 

 

В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Notify client when a table was full
Следующее
От: hmidi slim
Дата:
Сообщение: Re: Notify client when a table was full