Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fIWYf-0005Cj-Vt for pgsql-general@arkaria.postgresql.org; Tue, 15 May 2018 09:47:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fIWYe-0001dR-KV for pgsql-general@arkaria.postgresql.org; Tue, 15 May 2018 09:47:48 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fIWYe-0001dI-9H for pgsql-general@lists.postgresql.org; Tue, 15 May 2018 09:47:48 +0000 Received: from mailout02.t-online.de ([194.25.134.17]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fIWYb-00060G-Ad for pgsql-general@lists.postgresql.org; Tue, 15 May 2018 09:47:46 +0000 Received: from fwd27.aul.t-online.de (fwd27.aul.t-online.de [172.20.26.132]) by mailout02.t-online.de (Postfix) with SMTP id 18DC341A7C40 for ; Tue, 15 May 2018 11:47:41 +0200 (CEST) Received: from musicman.homeip.net (EwM3kZZrwhEq5SqalK4pLTq0T0HO6V16WlX7+bFnJdwFt0K1hhIqwwXGW47dw9OQlU@[91.7.23.197]) by fwd27.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384 encrypted) esmtp id 1fIWYP-2ZSAJk0; Tue, 15 May 2018 11:47:33 +0200 Received: (qmail 18279 invoked by uid 0); 15 May 2018 09:46:32 -0000 Received: from 192.168.75.32 by amadeus4 (envelope-from , uid 82) with qmail-scanner-1.24 (sophos: 5.38.0/3.69.2/5.43. localrules: ???. Clear:RC:1(192.168.75.32):. Processed in 0.062633 secs); 15 May 2018 09:46:32 -0000 Received: from unknown (HELO noten19) (192.168.75.32) by amadeus4.local with SMTP; 15 May 2018 09:46:32 -0000 Received: (qmail 20414 invoked by uid 1000); 15 May 2018 09:46:31 -0000 Date: 15 May 2018 09:46:31 -0000 From: hamann.w@t-online.de Subject: Re: Control PhoneNumber Via SQL To: pgsql-general@lists.postgresql.org Message-Id: X-Mailer: TkMail 4.0beta9 Content-type: text/plain; charset=utf-8 In-Reply-To: X-Qmail-Scanner-1.24: added fake MIME-Version header MIME-Version: 1.0 X-ID: EwM3kZZrwhEq5SqalK4pLTq0T0HO6V16WlX7+bFnJdwFt0K1hhIqwwXGW47dw9OQlU X-TOI-MSGID: 49505885-0c1f-431d-8b06-18669da54b12 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >> 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 >>