pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedCONCAT function adding extra characters
9+ messages / 6 participants
[nested] [flat]
* CONCAT function adding extra characters
@ 2021-06-15 18:55 AI Rumman <rummandba@gmail.com>
0 siblings, 5 replies; 9+ messages in thread
From: AI Rumman @ 2021-06-15 18:55 UTC (permalink / raw)
To: pgsql-general
I am using Postgresql 10 and seeing a strange behavior in CONCAT function
when I am concatenating double precision and int with a separator.
select concat('41.1'::double precision,':', 20);
> Result:
> 41.1000000000000014:20
Value 41.1 which double precision converts to 41.1000000014.
Is that expected?
Thanks.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: CONCAT function adding extra characters
@ 2021-06-15 19:00 Pavel Stehule <pavel.stehule@gmail.com>
parent: AI Rumman <rummandba@gmail.com>
4 siblings, 1 reply; 9+ messages in thread
From: Pavel Stehule @ 2021-06-15 19:00 UTC (permalink / raw)
To: AI Rumman <rummandba@gmail.com>; +Cc: pgsql-general
Hi
út 15. 6. 2021 v 20:56 odesílatel AI Rumman <rummandba@gmail.com> napsal:
> I am using Postgresql 10 and seeing a strange behavior in CONCAT function
> when I am concatenating double precision and int with a separator.
>
> select concat('41.1'::double precision,':', 20);
>> Result:
>> 41.1000000000000014:20
>
>
> Value 41.1 which double precision converts to 41.1000000014.
>
> Is that expected?
>
this is strange
postgres=# select concat('41.1'::double precision,':', 20);
┌─────────┐
│ concat │
╞═════════╡
│ 41.1:20 │
└─────────┘
(1 row)
postgres=# select version();
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ version
│
╞═══════════════════════════════════════════════════════════════════════════════════════════════════════════╡
│ PostgreSQL 10.17 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 11.1.1
20210428 (Red Hat 11.1.1-1), 64-bit │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(1 row)
Regards
Pavel
> Thanks.
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: CONCAT function adding extra characters
@ 2021-06-15 19:05 Adrian Klaver <adrian.klaver@aklaver.com>
parent: AI Rumman <rummandba@gmail.com>
4 siblings, 0 replies; 9+ messages in thread
From: Adrian Klaver @ 2021-06-15 19:05 UTC (permalink / raw)
To: AI Rumman <rummandba@gmail.com>; pgsql-general
On 6/15/21 11:55 AM, AI Rumman wrote:
> I am using Postgresql 10 and seeing a strange behavior in CONCAT
> function when I am concatenating double precision and int with a separator.
>
> select concat('41.1'::double precision,':', 20);
> Result:
> 41.1000000000000014:20
>
>
> Value 41.1 which double precision converts to 41.1000000014.
>
> Is that expected?
No.
What OS and version of same?
How was Postgres installed?
>
> Thanks.
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: CONCAT function adding extra characters
@ 2021-06-15 19:07 Adrian Klaver <adrian.klaver@aklaver.com>
parent: AI Rumman <rummandba@gmail.com>
4 siblings, 0 replies; 9+ messages in thread
From: Adrian Klaver @ 2021-06-15 19:07 UTC (permalink / raw)
To: AI Rumman <rummandba@gmail.com>; pgsql-general
On 6/15/21 11:55 AM, AI Rumman wrote:
> I am using Postgresql 10 and seeing a strange behavior in CONCAT
> function when I am concatenating double precision and int with a separator.
>
> select concat('41.1'::double precision,':', 20);
> Result:
> 41.1000000000000014:20
>
>
> Value 41.1 which double precision converts to 41.1000000014.
>
> Is that expected?
Aah, too quick on the trigger.
Also:
Is there a home brewed version of CONCAT() in the search_path?
>
> Thanks.
--
Adrian Klaver
adrian.klaver@aklaver.com
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: CONCAT function adding extra characters
@ 2021-06-15 19:07 Tom Lane <tgl@sss.pgh.pa.us>
parent: AI Rumman <rummandba@gmail.com>
4 siblings, 1 reply; 9+ messages in thread
From: Tom Lane @ 2021-06-15 19:07 UTC (permalink / raw)
To: AI Rumman <rummandba@gmail.com>; +Cc: pgsql-general
AI Rumman <rummandba@gmail.com> writes:
> I am using Postgresql 10 and seeing a strange behavior in CONCAT function
> when I am concatenating double precision and int with a separator.
> select concat('41.1'::double precision,':', 20);
>> Result:
>> 41.1000000000000014:20
What have you got extra_float_digits set to?
regards, tom lane
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: CONCAT function adding extra characters
@ 2021-06-15 19:12 Kenneth Marshall <ktm@rice.edu>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: Kenneth Marshall @ 2021-06-15 19:12 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: AI Rumman <rummandba@gmail.com>; pgsql-general
> út 15. 6. 2021 v 20:56 odesílatel AI Rumman <rummandba@gmail.com> napsal:
> I am using Postgresql 10 and seeing a strange behavior in CONCAT function
> when I am concatenating double precision and int with a separator.
>
> select concat('41.1'::double precision,':', 20);
>> Result:
>> 41.1000000000000014:20
>
>
> Value 41.1 which double precision converts to 41.1000000014.
>
> Is that expected?
>
Hi
0.1 cannot be represented exactly in binary so that does not look out of
line. There are also some config options for extra digits and what not
that may affect the result of a cast.
Regards,
Ken
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: CONCAT function adding extra characters
@ 2021-06-15 19:18 Pavel Stehule <pavel.stehule@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 9+ messages in thread
From: Pavel Stehule @ 2021-06-15 19:18 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: AI Rumman <rummandba@gmail.com>; pgsql-general
út 15. 6. 2021 v 21:07 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:
> AI Rumman <rummandba@gmail.com> writes:
> > I am using Postgresql 10 and seeing a strange behavior in CONCAT function
> > when I am concatenating double precision and int with a separator.
>
> > select concat('41.1'::double precision,':', 20);
> >> Result:
> >> 41.1000000000000014:20
>
> What have you got extra_float_digits set to?
>
>
postgres=# set extra_float_digits to 3;
SET
postgres=# select concat('41.1'::double precision,':', 20);
┌────────────────────────┐
│ concat │
╞════════════════════════╡
│ 41.1000000000000014:20 │
└────────────────────────┘
(1 row)
Pavel
> regards, tom lane
>
>
>
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: CONCAT function adding extra characters
@ 2021-06-15 20:14 Ron <ronljohnsonjr@gmail.com>
parent: AI Rumman <rummandba@gmail.com>
4 siblings, 0 replies; 9+ messages in thread
From: Ron @ 2021-06-15 20:14 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
On 6/15/21 1:55 PM, AI Rumman wrote:
> I am using Postgresql 10 and seeing a strange behavior in CONCAT function
> when I am concatenating double precision and int with a separator.
>
> select concat('41.1'::double precision,':', 20);
> Result:
> 41.1000000000000014:20
>
>
> Value 41.1 which double precision converts to 41.1000000014.
>
> Is that expected?
Because of the well-known difficulty in precisely converting floating point
to decimal, in cases like this, I always cast to NUMERIC of the desired
precision. It's the COBOL programmer in me...
--
Angular momentum makes the world go 'round.
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: CONCAT function adding extra characters
@ 2021-06-15 21:29 AI Rumman <rummandba@gmail.com>
parent: Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: AI Rumman @ 2021-06-15 21:29 UTC (permalink / raw)
To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general
I saw that problem when I was running the query from DBeaver.
Got my answer.
Thanks & Regards.
On Tue, Jun 15, 2021 at 12:18 PM Pavel Stehule <pavel.stehule@gmail.com>
wrote:
>
>
> út 15. 6. 2021 v 21:07 odesílatel Tom Lane <tgl@sss.pgh.pa.us> napsal:
>
>> AI Rumman <rummandba@gmail.com> writes:
>> > I am using Postgresql 10 and seeing a strange behavior in CONCAT
>> function
>> > when I am concatenating double precision and int with a separator.
>>
>> > select concat('41.1'::double precision,':', 20);
>> >> Result:
>> >> 41.1000000000000014:20
>>
>> What have you got extra_float_digits set to?
>>
>>
> postgres=# set extra_float_digits to 3;
> SET
> postgres=# select concat('41.1'::double precision,':', 20);
> ┌────────────────────────┐
> │ concat │
> ╞════════════════════════╡
> │ 41.1000000000000014:20 │
> └────────────────────────┘
> (1 row)
>
> Pavel
>
>
>
>> regards, tom lane
>>
>>
>>
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2021-06-15 21:29 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-06-15 18:55 CONCAT function adding extra characters AI Rumman <rummandba@gmail.com>
2021-06-15 19:00 ` Pavel Stehule <pavel.stehule@gmail.com>
2021-06-15 19:12 ` Kenneth Marshall <ktm@rice.edu>
2021-06-15 19:05 ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-06-15 19:07 ` Adrian Klaver <adrian.klaver@aklaver.com>
2021-06-15 19:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-06-15 19:18 ` Pavel Stehule <pavel.stehule@gmail.com>
2021-06-15 21:29 ` AI Rumman <rummandba@gmail.com>
2021-06-15 20:14 ` Ron <ronljohnsonjr@gmail.com>
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