Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ecYs9-0002w3-2o for pgsql-general@arkaria.postgresql.org; Fri, 19 Jan 2018 15:46:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ecYs8-0006G8-GR for pgsql-general@arkaria.postgresql.org; Fri, 19 Jan 2018 15:46:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ecYs8-0006Fv-5f for pgsql-general@lists.postgresql.org; Fri, 19 Jan 2018 15:46:28 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1ecYs5-00047R-0i for pgsql-general@postgresql.org; Fri, 19 Jan 2018 15:46:26 +0000 Received: by mail-wm0-x232.google.com with SMTP id 141so4378146wme.3 for ; Fri, 19 Jan 2018 07:46:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version:thread-index :content-language; bh=TsCfF60SPZ5Y98MbZp2eUgMpX1Hc8NIybFMyk386Uc0=; b=Z4zXvDDbLT3QXqXVucUTRuNDMgrcfS8YRjTpq01TRq19tFM7WgzYzZh6tdvFnAlrzH ulYaHNBOJtWM8mXmITbHQG1JHb9sSf0qEbYSonbGyZbf1lEU8XduwRTz4Et66C5Lmw39 qk5i7/sFxjzfdeFUe5MzVazOlW70tB2JpOhi/vPKWvtA8nCd/OUhxp6/0cq5oj3svP2P peWmqDBwTCT3hhLEOnuSTqenAAcVT+pRJkXxu4nDup9m8TobW6iHpEX8KNJcuy7yvzGf XC/GQDK0mp4E/GL62ZaHG9nb21T5F0G3Md8aVkcMRTsjb3in95vPb232ESvS4FpAxpzJ gb1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :thread-index:content-language; bh=TsCfF60SPZ5Y98MbZp2eUgMpX1Hc8NIybFMyk386Uc0=; b=hhOjo9A0Yau6TEHZlBZDR43GUw2NQe9254OjDw4x8zRwoYgUoQAAgiliDgha+I4tYG VWPqTOpSPZEV0wblAqc8Z8el8lR3CMNUCK4swSbGVw2Os1r48GfGdNEdHylJ81ruibDS okDdwgOsZJzSi0QO8LV0V95bsFxmfU5bsnhYECp2jZb9aZMv0dpmDnQ1cp0pYKvI79yB icb0pjbvmE1CUEfi5xI4FsYmA9tRyiKAwj0PkHekn8GG3wycTrF6LinJ/zX3/zYSA3Ux K84E0j2u561bwo2iwjSIzHt6o4FgubkP1jm7N5ObJcY7J+Po1OihBuo/xfHORlMITF6Q bQYA== X-Gm-Message-State: AKwxytfyTLLNKUShA6t4/aKCAJn42MezWhkzNN4tlth/klFq1b2SZhCg pq3l4410mumHni1dhOc0hWLf3g== X-Google-Smtp-Source: ACJfBotqW7/Eued8S//SYUW5ubwT76OS03+oy1QqY6dIR0wvNjfsTMxzKJBimrhKzagVy7ZDynhCEw== X-Received: by 10.80.152.161 with SMTP id j30mr13724617edb.280.1516376782979; Fri, 19 Jan 2018 07:46:22 -0800 (PST) Received: from PC016 (mail.ibeq.com. [212.100.42.241]) by smtp.gmail.com with ESMTPSA id g21sm6685775edg.88.2018.01.19.07.46.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Jan 2018 07:46:22 -0800 (PST) From: To: Subject: Use left hand column for null values Date: Fri, 19 Jan 2018 16:46:21 +0100 Message-ID: <006801d3913c$a7b7c420$f7274c60$@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0069_01D39145.097C2C20" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdORO8pxc1kK52TaQPO+a0uhwNi6Ng== Content-Language: de List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multipart message in MIME format. ------=_NextPart_000_0069_01D39145.097C2C20 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 ------=_NextPart_000_0069_01D39145.097C2C20 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

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

 

 

------=_NextPart_000_0069_01D39145.097C2C20--