Re: Control PhoneNumber Via SQL

From: tango ward <tangoward15(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "raf(at)raf(dot)org" <raf(at)raf(dot)org>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Control PhoneNumber Via SQL
Date: 2018-05-16 05:48:44
Message-ID: CAA6wQLKt2vL4hWyf5=Y3xCFN7ft6xxH5Jkz4QAhTmX=eOZ+QeA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, May 16, 2018 at 9:04 AM, tango ward <tangoward15(at)gmail(dot)com> wrote:

> Okay, I figured it out.
>
> cur_t.execute("""
> SELECT
> CASE
> WHEN mobilenumber ~'^0[1-9]'
> THEN regexp_replace(mobilenumber, '0', '+63')
> ELSE mobilenumber
> END
> FROM studeprofile
> ORDER BY lastname
> """)
>
> In my previous SELECT statement, I picked the mobilenumber before running
> a CASE statement to it instead of jumping directly to CASE statement after
> SELECT.
>
>
>
Sorry, just clarification for regexp_replace, is it possible to replace two
character without making nested regexp_replace?

I have a phone number with the following format: 09xxxxxxxxx/09xxxxxxxxxx

cur_t.execute("""
SELECT firstname, lastname,
CASE
WHEN mobilenumber ~'^0[1-9]'
THEN regexp_replace(mobilenumber, '[0/0]', '+63')
WHEN mobilenumber ~'^9[0-9]' AND LENGTH(mobilenumber) = 10
THEN '+63' || mobilenumber
ELSE mobilenumber
END
FROM studeprofile
ORDER BY lastname
""")

I can't make the /09 to be replaced by /+63 or +63. The brackets in regex
as defined https://regexr.com/, it says any of the characters inside the
brackets. I think i'm missing something.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Philipp Kraus 2018-05-16 06:14:45 array_agg to array
Previous Message Łukasz Jarych 2018-05-16 04:52:17 Re: Function to set up variable inside it