Re: Control PhoneNumber Via SQL

Поиск
Список
Период
Сортировка
От hamann.w@t-online.de
Тема Re: Control PhoneNumber Via SQL
Дата
Msg-id wolfgang-1180515114631.A032808@noten19.local
обсуждение исходный текст
Ответ на Control PhoneNumber Via SQL  (tango ward <tangoward15@gmail.com>)
Ответы Re: Control PhoneNumber Via SQL  (raf@raf.org)
Список pgsql-general
>> 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
>> 






В списке pgsql-general по дате отправления:

Предыдущее
От: tango ward
Дата:
Сообщение: Control PhoneNumber Via SQL
Следующее
От: Łukasz Jarych
Дата:
Сообщение: Function to set up variable inside it