pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Gabriel Furstenheim Milerud <furstenheim@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-general@postgresql.org>
Subject: Re: Converting to number with given format
Date: Wed, 19 Sep 2018 07:07:05 -0700
Message-ID: <fec75866-e508-91f1-5298-4db4ab605021@aklaver.com> (raw)
In-Reply-To: <CAJN3DWqxXTkduu2itfq9yoKP9zAC5N-PXMJ4OuJJrPciCk5Wtg@mail.gmail.com>
References: <CAJN3DWrePeKge2-e6NPTkHSpXfndCu7JdKBwALUpMkjKx7dm=Q@mail.gmail.com>
	<aa556ef6-2c98-1837-9799-7e0715268ba9@aklaver.com>
	<CAJN3DWp38h+TCgivCw86ESf_Z8+OmrYPtdgsVKpx8-k3G=TqHA@mail.gmail.com>
	<a038d40a-0d4b-1df0-f3c3-29e36489aeb9@aklaver.com>
	<CAJN3DWqxXTkduu2itfq9yoKP9zAC5N-PXMJ4OuJJrPciCk5Wtg@mail.gmail.com>

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




view thread (9+ messages)  latest in thread

Message-ID: <fec75866-e508-91f1-5298-4db4ab605021@aklaver.com>
Permalink:  ../fec75866-e508-91f1-5298-4db4ab605021@aklaver.com/
Also on:    postgresql.org/message-id/fec75866-e508-91f1-5298-4db4ab605021@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, furstenheim@gmail.com
  Subject: Re: Converting to number with given format
  In-Reply-To: <fec75866-e508-91f1-5298-4db4ab605021@aklaver.com>
  References: <CAJN3DWrePeKge2-e6NPTkHSpXfndCu7JdKBwALUpMkjKx7dm=Q@mail.gmail.com> <aa556ef6-2c98-1837-9799-7e0715268ba9@aklaver.com> <CAJN3DWp38h+TCgivCw86ESf_Z8+OmrYPtdgsVKpx8-k3G=TqHA@mail.gmail.com> <a038d40a-0d4b-1df0-f3c3-29e36489aeb9@aklaver.com> <CAJN3DWqxXTkduu2itfq9yoKP9zAC5N-PXMJ4OuJJrPciCk5Wtg@mail.gmail.com> <fec75866-e508-91f1-5298-4db4ab605021@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox