pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Moreno Andreo <moreno.andreo@evolu-s.it>
To: pgsql-general@lists.postgresql.org
Subject: Re: CASE(?) to write in a different column based on a string pattern
Date: Wed, 13 Nov 2019 18:03:37 +0100
Message-ID: <c69b90ad-da88-c031-1694-d47da0f2df86@evolu-s.it> (raw)
In-Reply-To: <CAEzk6ff14JeGb0MtbGZLq2vSJ7SrnNE6FzABsRrkb_n592E-YQ@mail.gmail.com>
References: <5bbe8366-bcd4-7f6f-94c8-ebc465c3b6b7@evolu-s.it>
	<CAEzk6ff14JeGb0MtbGZLq2vSJ7SrnNE6FzABsRrkb_n592E-YQ@mail.gmail.com>

Il 13/11/19 17:36, Geoff Winkless ha scritto:
>
> Simplest way in plain SQL would be individual case statements for each
> column, I think.
>
> SELECT pattern,
>    CASE WHEN pattern LIKE 'foo%' THEN SUBSTR(pattern, 4) ELSE '' END AS foo
>    CASE WHEN pattern LIKE 'bar%' THEN SUBSTR(pattern, 4) ELSE '' END AS bar
>    CASE WHEN pattern LIKE 'baz%' THEN SUBSTR(pattern, 4) ELSE '' END AS baz
> FROM tbl;
>
> Geoff
>
>
Geoff,
     it worked perfectly!

Thanks a lot!
Moreno.-






view thread (5+ messages)

Message-ID: <c69b90ad-da88-c031-1694-d47da0f2df86@evolu-s.it>
Permalink:  ../c69b90ad-da88-c031-1694-d47da0f2df86@evolu-s.it/
Also on:    postgresql.org/message-id/c69b90ad-da88-c031-1694-d47da0f2df86@evolu-s.it

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: moreno.andreo@evolu-s.it
  Subject: Re: CASE(?) to write in a different column based on a string pattern
  In-Reply-To: <c69b90ad-da88-c031-1694-d47da0f2df86@evolu-s.it>
  References: <5bbe8366-bcd4-7f6f-94c8-ebc465c3b6b7@evolu-s.it> <CAEzk6ff14JeGb0MtbGZLq2vSJ7SrnNE6FzABsRrkb_n592E-YQ@mail.gmail.com> <c69b90ad-da88-c031-1694-d47da0f2df86@evolu-s.it>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox