Re: CASE(?) to write in a different column based on a string pattern

From: Moreno Andreo <moreno(dot)andreo(at)evolu-s(dot)it>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: CASE(?) to write in a different column based on a string pattern
Date: 2019-11-13 17:03:37
Message-ID: c69b90ad-da88-c031-1694-d47da0f2df86@evolu-s.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.-

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Durumdara 2019-11-13 17:57:36 Last autovacuum time - what is it?
Previous Message Moreno Andreo 2019-11-13 17:00:14 Re: CASE(?) to write in a different column based on a string pattern