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 1g2c2l-0005yu-AT for pgsql-general@arkaria.postgresql.org; Wed, 19 Sep 2018 12:57:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g2c2j-0007dS-If for pgsql-general@arkaria.postgresql.org; Wed, 19 Sep 2018 12:57:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2c2h-0007dJ-CV for pgsql-general@lists.postgresql.org; Wed, 19 Sep 2018 12:57:21 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g2c2Z-00069u-Ty for pgsql-general@postgresql.org; Wed, 19 Sep 2018 12:57:18 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 5BDBB2118B; Wed, 19 Sep 2018 08:57:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 19 Sep 2018 08:57:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=ePRDARi1icdFrHwdXJYNSBg19klOd n7GSMGrAGfTYYA=; b=LQocANDAqtwWkARTo5GF00/BgNFrXpa1o+BrVBLsHd3qq IPw9e+YdZmCeDjzCz7Q6oluLZZvdcNclI/4pOVG4ohvSGJ1EpS4pBJeUmZnU7xlY AwKOurjHdLIgnazXd9JiD9Y4Lm0IhE+ETSM0rSfCG/EIrw5QtWfJsIRUFBrHfEKX nD3TdesiaZADdaBjpsY+fZwtFP+nsMM4jxJnCB56w38Fndc0vTNOu+0omzT3yQWZ ssROkcLW4bsGIQVB5qPzd4BOk4NXVHmfNpwsGthVsuVCsIxJbzydj53tHC63ebao cD4xY1GqIRJo4/aI97REV9srCg09IreewHksrncrg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=ePRDAR i1icdFrHwdXJYNSBg19klOdn7GSMGrAGfTYYA=; b=fBKL0Pj/CpxlPSxEYZO0Um tQrojmd2zJpbVZKPTHUYTLw/qir0SVLjqg9w/OMBPNWlrPDta4Z1xNA4jY2i6LQI KSiLr6CiqhSwdBdN7HtMUKt+LAUnNG/BDyAwjP4SHXWfTUCrgXGmp/InFqboVv4Q 54tSC1y3mL2+KTBmz45NjorvXZdws+P/wNdcehvXlSWYXGrC+VyU6uLb22sMwbjG ylkVDW+uYTbPyGvRpKrWJ4k0E7drMWsrN0j2B/m5u843TcQNLUDUnPAC+10tP6nZ khaAMDXzeAfboltay7n6y/9b+XYRZway4+7isTo6/NHbCmkX80K627OXL/qf9+gg == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id 9978EE4680; Wed, 19 Sep 2018 08:57:08 -0400 (EDT) Subject: Re: Converting to number with given format To: Gabriel Furstenheim Milerud , PostgreSQL mailing lists References: From: Adrian Klaver Message-ID: Date: Wed, 19 Sep 2018 05:57:07 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/19/18 5:38 AM, Gabriel Furstenheim Milerud wrote: > Hello, > I'd like to convert a string number to a number being able to provide > the custom format. > With dates it works perfectly fine, so that I can do: > > SELECT to_date('18 09 10', 'YY MM DD') > > Is there something similar with numbers? > > SELECT to_number('9,000',some_format) =9; SELECT to_number('9,000', '9V3')::int; to_number ----------- 9 > SELECT to_number('9,000',another_format) =9000; SELECT to_number('9,000', '99999'); to_number ----------- 9000 > > It is not clear to me what some_format should be and what another_format > should be so that those selects are equal. > > I've read the documentation but I can't find a similar example. In > stackoverflow they don't provide a solution either: > https://stackoverflow.com/questions/18882942/postgresql-convert-a-string-with-commas-into-an-integer > > Thanks > Gabriel Fürstenheim -- Adrian Klaver adrian.klaver@aklaver.com