From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Gabriel Furstenheim Milerud <furstenheim@gmail.com>
To: PostgreSQL mailing lists <pgsql-general@postgresql.org>
Subject: Re: Converting to number with given format
Date: Wed, 19 Sep 2018 05:57:07 -0700
Message-ID: <aa556ef6-2c98-1837-9799-7e0715268ba9@aklaver.com> (raw)
In-Reply-To: <CAJN3DWrePeKge2-e6NPTkHSpXfndCu7JdKBwALUpMkjKx7dm=Q@mail.gmail.com>
References: <CAJN3DWrePeKge2-e6NPTkHSpXfndCu7JdKBwALUpMkjKx7dm=Q@mail.gmail.com>
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
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: <aa556ef6-2c98-1837-9799-7e0715268ba9@aklaver.com>
References: <CAJN3DWrePeKge2-e6NPTkHSpXfndCu7JdKBwALUpMkjKx7dm=Q@mail.gmail.com> <aa556ef6-2c98-1837-9799-7e0715268ba9@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