Re: Converting to number with given format - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Converting to number with given format
Date
Msg-id fec75866-e508-91f1-5298-4db4ab605021@aklaver.com
Whole thread Raw
In response to Re: Converting to number with given format  (Gabriel Furstenheim Milerud <furstenheim@gmail.com>)
List pgsql-general
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


pgsql-general by date:

Previous
From: Fabio Pardi
Date:
Subject: Re: Pgbouncer and postgres
Next
From: Raghavendra Rao J S V
Date:
Subject: Which is the most stable PostgreSQL version yet present for CentOS 7?