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 1g2d9W-0001FR-KG for pgsql-general@arkaria.postgresql.org; Wed, 19 Sep 2018 14:08:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g2d9U-0002Pz-KA for pgsql-general@arkaria.postgresql.org; Wed, 19 Sep 2018 14:08:24 +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 1g2d8Q-00066a-RE for pgsql-general@lists.postgresql.org; Wed, 19 Sep 2018 14:07:20 +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 1g2d8H-0007tf-3a for pgsql-general@postgresql.org; Wed, 19 Sep 2018 14:07:17 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 2607221CE2; Wed, 19 Sep 2018 10:07:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 19 Sep 2018 10:07:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc: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=Irupzag0idH6yHz3QaN4Hy1Fjj/eD bNIGCN7YiyGC5A=; b=r2qeLHOUHc2iOgqZ16KDz8ADbWjnk5BLuHi64Qg0f7F2A HtN/H4XaZsifvJQhhtlZRT2aYQR2uCfaxqf5lmsQuchehOwMMriEbRv0lGWLYeqO G2sehUS2zT1PwamSrhlFhXn5BNkm34YN3b6vWw5q1LBKvZ6E9iWwt+6HRSUQWRtZ 1Q4TMktRCCSNxdJLdzL0wq9OidYtbuUl/+I8Nd2JqX1EThtBPxQ72F283IYq+V2b 9IX2+owXXrgY5sVd3NV0LiqTZKOaWkE1f4bTXYSzNX8I6MVwjYXCxdR5D05V0HNx eYUqzkfdZ7gSyQ8NmKIoEUNlTNSJuQ2vIrMaJ9i/g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=Irupza g0idH6yHz3QaN4Hy1Fjj/eDbNIGCN7YiyGC5A=; b=YOvPSx2X9BfWBrtIRQjQzl IeSyK5NV68JhZSSn0FKAk/UP8ws+TU+q46WZmp+enY1qpOvQdPHk3tMY9M4BAbWe SmY2hw7qocJo9pUv+xzFJ+F8FwG5NldWcDQKx3vgsflpttZwaJl9FQvk656KAvq4 dUroNUBgjVEgENW+tLCvWYNiEzNvak9DauKbDzIJFKRoDiD7YcozFYd/mQtiUwqB 4p7TtlWSn8nIwvyMOfD9IMsRm7vkCSg7NC5FSclHijUt4KqxP4SexlAdSMtcZaBH Pnfr4cyUXpWESk6ew4wpRTHSaVwTE/idEoQ7Hm15v6kgrFMSuUnuOq23oyX0gsaw == 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 EDAC1E4680; Wed, 19 Sep 2018 10:07:05 -0400 (EDT) Subject: Re: Converting to number with given format To: Gabriel Furstenheim Milerud Cc: PostgreSQL mailing lists References: From: Adrian Klaver Message-ID: Date: Wed, 19 Sep 2018 07:07:05 -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: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/19/18 6:33 AM, Gabriel Furstenheim Milerud wrote: > Sorry, > So basically what I'm trying to achieve is the following. There is an > input file from the user and a configuration describing what is being > inserted. For example, he might have Last activity which is 'YYYY-MM-DD > HH:mi:ss' and Join date which is only 'YYYY-MM-DD' because there is no > associated timing. For dates this works perfectly and it is possible to > configure what the input from the user will be. Think it is as a > dropdown where the user says, this is the kind of data that I have. > > Maybe that is not possible with numbers? To say in a format something > like "my numbers have comma as decimal separator and no thousands > separators" or "my numbers are point separated and have comma as > thousands separator" Yeah that is a problem because it depends on the locale information in the database you are entering the data: show lc_numeric; lc_numeric ------------ en_US select to_number('10.000,00', '99999D00'); to_number ----------- 10.00 select to_number('10.000,00', '99999.00'); to_number ----------- 10.00 set lc_numeric = 'de_DE'; SET select to_number('10.000,00', '99999D00'); to_number ----------- 10000.0 select to_number('10.000,00', '99999.00'); to_number ----------- 10.00 D and G(group separator) work using the locale information set in the database. I know of no way to pass the information in with the format string. Off the top of my head I would say that this conversion would need to be done at point of input. Have user select their decimal and group separators and then convert to a universal format. > > Nice thing of having a string for the format is that I can use it as a > parameter for a prepared statement. > > Thanks > > -- Adrian Klaver adrian.klaver@aklaver.com