pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hamann.w@t-online.de
To: pgsql-general@lists.postgresql.org
Subject: Re: Control PhoneNumber Via SQL
Date: 15 May 2018 09:46:31 -0000
Message-ID: <wolfgang-1180515114631.A032808@noten19.local> (raw)
In-Reply-To: <CAA6wQLKUGns3pBaukYHnkXTKmMVadrtgprUMhV+R0iQQy86chQ@mail.gmail.com>

>> Hi,
>> 
>> Sorry for asking question again.
>> 
>> I would like to know if it is possible to control the phone number in SQL
>> before inserting it to the destination DB?
>> 
>> I have a model in Django:
>> 
>> class BasePerson(TimeStampedModel):
>>  phone_number = PhoneNumberField(max_length=50, verbose_name=_(u'phone
>> number'), blank=True)
>> 
>> 
>> The data for phone number that I am migrating doesn't have country code. I
>> want to determine first if the number has country code in it, if it doesn't
>> then I will add the country code on the number before INSERTING it to the
>> destination database.
>> 
Hi, something like
insert into newtable (phone, ...)
 select case when phone ~ '^0[1-9]' then regex_replace('0', '+49', phone) else
  case when phone ~ '^00' then regex_replace('00', '+', phone) else phone end end, ...
 from oldtable;

Regards
Wolfgang

>> Any suggestion will be highly appreciated.
>> 
>> 
>> Thanks,
>> J
>> 








view thread (16+ messages)  latest in thread

Message-ID: <wolfgang-1180515114631.A032808@noten19.local>
Permalink:  ../wolfgang-1180515114631.A032808@noten19.local/
Also on:    postgresql.org/message-id/wolfgang-1180515114631.A032808@noten19.local

 · 

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: hamann.w@t-online.de
  Subject: Re: Control PhoneNumber Via SQL
  In-Reply-To: <wolfgang-1180515114631.A032808@noten19.local>
  References: <CAA6wQLKUGns3pBaukYHnkXTKmMVadrtgprUMhV+R0iQQy86chQ@mail.gmail.com> <wolfgang-1180515114631.A032808@noten19.local>

* 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