Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 6BE5CA7D6D for ; Mon, 20 Feb 2012 11:17:27 -0400 (AST) Received: from mail-iy0-f174.google.com ([209.85.210.174]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RzUzU-0005vL-NZ for pgsql-sql@postgresql.org; Mon, 20 Feb 2012 15:17:26 +0000 Received: by iacb35 with SMTP id b35so7607810iac.19 for ; Mon, 20 Feb 2012 07:17:11 -0800 (PST) Received-SPF: pass (google.com: domain of filip.rembialkowski@gmail.com designates 10.42.147.199 as permitted sender) client-ip=10.42.147.199; Authentication-Results: mr.google.com; spf=pass (google.com: domain of filip.rembialkowski@gmail.com designates 10.42.147.199 as permitted sender) smtp.mail=filip.rembialkowski@gmail.com; dkim=pass header.i=filip.rembialkowski@gmail.com Received: from mr.google.com ([10.42.147.199]) by 10.42.147.199 with SMTP id o7mr21819354icv.50.1329751031183 (num_hops = 1); Mon, 20 Feb 2012 07:17:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=ud1CLhKiC4qNH2ACdYFMl/aQxAhiOc6fbNAHHa4bdp4=; b=k6gQG40RVgEmuyXswxrbRFKz18rkFYcg4ss7FthU8rxRRP8D8KhSWZmq93kiEuFayQ 43+hIXMoHCKvvNYDY02Kr15xT985jBjYo3YyGr2nGbbz4dJiUctZvZ63MFYqzEg7FO6Q nbsJyp1gjznMSATOITlAiaItqupYAefgBuC1A= Received: by 10.42.147.199 with SMTP id o7mr17447669icv.50.1329751031111; Mon, 20 Feb 2012 07:17:11 -0800 (PST) Received: from [127.0.0.1] ([217.98.89.132]) by mx.google.com with ESMTPS id 5sm28517253ibe.8.2012.02.20.07.17.09 (version=SSLv3 cipher=OTHER); Mon, 20 Feb 2012 07:17:10 -0800 (PST) Message-ID: <4F4263F7.5050508@gmail.com> Date: Mon, 20 Feb 2012 16:17:11 +0100 From: =?UTF-8?B?RmlsaXAgUmVtYmlhxYJrb3dza2k=?= User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2.27) Gecko/20120216 Thunderbird/3.1.19 MIME-Version: 1.0 To: Andreas CC: pgsql-sql@postgresql.org Subject: Re: How to split up phone numbers? References: <4F425DB9.3060604@gmx.net> In-Reply-To: <4F425DB9.3060604@gmx.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201202/62 X-Sequence-Number: 36355 At 2012-02-20 15:50, Andreas wrote: > Hi, > is there a way to split up phone numbers? > I know that's a tricky topic and it depends on the national phone > number format. > I'm especially interested in a solution for Germany, Swizerland and > Austria. > > I've got everything in a phone number column that makes hardly sense > like: > +49432156780 > 0049 4321 5678 0 > 04321/5678-0 > and so on... > Those 3 samples are actually the same number in different notations. > > Aim would be to get a normalized number split up in 4 seperate columns > nr_nation > nr_city > nr_main > nr_individual > > so I end up with > 49 4321 5678 0 for central > 49 4321 5678 42 for Mr. Smith > > Is this doable? > yes, sure - with regular expressions and/or with bunch of IF/THEN/ELSE blocks in PL/PgSQL. see regexp_split_to_array, and other regex functions in the manual: http://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP