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 1g2ksp-0007o7-3R for pgsql-general@arkaria.postgresql.org; Wed, 19 Sep 2018 22:23:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g2ksm-0003dr-AM for pgsql-general@arkaria.postgresql.org; Wed, 19 Sep 2018 22:23:40 +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 1g2ksl-0003di-T5 for pgsql-general@lists.postgresql.org; Wed, 19 Sep 2018 22:23:40 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g2ksj-0004q4-7H for pgsql-general@postgresql.org; Wed, 19 Sep 2018 22:23:38 +0000 Received: by mail-pl1-x62f.google.com with SMTP id u11-v6so3312173plq.5 for ; Wed, 19 Sep 2018 15:23:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=AOu6Yk0V5k6VXOIS/B0S84NxG/7r6wu4PAszX7gfIvw=; b=UvlapBuOrilrnqdU+3JTdw52yHJOrVHKCm8l5MDax4p9+QuTOm13V/d7IqJRIm4hAF eqewfYC6A5pquQ1yBjWtjt5JX6vfq8rBpfvRq6YNS+jAMlhVQRn4KlAonCMleQqMZuiI Lwn3CApsi9UvB18vaS5PWLvQ0CSdmOuKBiXSljIajDk39W5LJswsol8GQaczxuqyJbNr FbeSsaCfOQTkNEYXN3JX0NS9MjDziqUU/Yf7UW+GenAVfszmRVk8lp17BHkS2fkabrz8 ysrZYpWASpw7dcIJiq/dC+/yYc8LETUPUdqUWdZUQzJH9AcBnBROZ+hQNbATYeirGOuE 6u9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=AOu6Yk0V5k6VXOIS/B0S84NxG/7r6wu4PAszX7gfIvw=; b=D5Cs5mvcrBp11+xSKDN9iEp7WrlX0vUCGwQUORnHFjX2nvJUjr+Ca3RD8rhzEDAEcd 8dy7eFMeO8gGKJ4yhULLv6/EAvmfEaxxbGmrsmQe+SJbpTmkYUzmeqAJTQmm5uX+a7W9 Houi+80ZEjAipwaNEHmuDrpUxnRLqTGl1pRpqguOwuMaxvBsuu7KZN6kQcdK7OBBtHtf BZvEGHQeFZAw+I7Its2HHn1jgnxSf+3H1MPWaxBS8/e1EazioAhMBwF2+ri0LaTkkkbj 7wTmzn3jyRMcwL7ET8t3EFyJme6StvzJNcMiQdtUdOr/Iywnp8wSd07hO/Kkcxgkei4o Y20w== X-Gm-Message-State: APzg51CHsAkkR7/zSMEOTwtyhSj4wXXZWfwHFMzF7va5/zRPHxPtiPvv Z2c4b/04zKa117/hpfMe3SkVfaI0 X-Google-Smtp-Source: ANB0VdZ467ctOqACBQQAOt73d0LUl06yWmx48oW8e4wQskhgLeqj3BOOHkmQhIfOZXQYRTul03X2Pg== X-Received: by 2002:a17:902:8308:: with SMTP id bd8-v6mr36073652plb.134.1537395815450; Wed, 19 Sep 2018 15:23:35 -0700 (PDT) Received: from tim-desktop (2001-44b8-31f2-bb00-28b0-4d19-5426-5124.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:28b0:4d19:5426:5124]) by smtp.gmail.com with ESMTPSA id f11-v6sm32584458pfa.131.2018.09.19.15.23.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:23:34 -0700 (PDT) References: User-agent: mu4e 0.9.18; emacs 26.1 From: Tim Cross To: Gabriel Furstenheim Milerud Cc: adrian.klaver@aklaver.com, PostgreSQL mailing lists Subject: Re: Converting to number with given format In-reply-to: Date: Thu, 20 Sep 2018 08:23:30 +1000 Message-ID: <87y3bxdt3x.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Gabriel Furstenheim Milerud writes: > 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" > > Nice thing of having a string for the format is that I can use it as a > parameter for a prepared statement. > I think this is normally something much better dealt with at the client level. Things like comma separator/grouping in numbers is really just a 'human' thing and is very locale dependent. The values 9,999 and 9999 are the same values. Things can quickly become complicated as you can have locale information at both the server and client end and they may not be the same. As you should always be sanitising your data before inserting into the database anyway, you may as well just add this as another check at the client end. Tim -- Tim Cross