Exponential notation bug

Started by Marcos Pegoraro9 months ago5 messages
#1Marcos Pegoraro
marcos@f10.com.br

I was deleting thousands of records each time with \gexec, then ...

This one works
select format('delete from table where ID = any(%L::integer[]);',
array_agg(ID)), (ord-1)/10000 from (
select * from generate_series(15e2,65e5) with ordinality) x(ID, ord) group
by 2 order by 2;

But it's easier to write in exponential notation, so I changed this
(ord-1)/10000 to (ord-1)/1e4. Using this way exponential notation is just
ignored.

regards
Marcos

#2Maciek Sakrejda
maciek@pganalyze.com
In reply to: Marcos Pegoraro (#1)
Re: Exponential notation bug

I took a look at simplifying this test case, and I think it comes down
to data types:

maciek=# select 9/10;
?column?
----------
0
(1 row)

maciek=# select pg_typeof(10);
pg_typeof
-----------
integer
(1 row)

But:

maciek=# select 9/1e1;
?column?
------------------------
0.90000000000000000000
(1 row)

maciek=# select pg_typeof(1e1);
pg_typeof
-----------
numeric
(1 row)

Does that explain the behavior you're seeing?

#3Robert Haas
robertmhaas@gmail.com
In reply to: Marcos Pegoraro (#1)
Re: Exponential notation bug

On Fri, Apr 4, 2025 at 11:55 AM Marcos Pegoraro <marcos@f10.com.br> wrote:

I was deleting thousands of records each time with \gexec, then ...

This one works
select format('delete from table where ID = any(%L::integer[]);', array_agg(ID)), (ord-1)/10000 from (
select * from generate_series(15e2,65e5) with ordinality) x(ID, ord) group by 2 order by 2;

But it's easier to write in exponential notation, so I changed this (ord-1)/10000 to (ord-1)/1e4. Using this way exponential notation is just ignored.

This seems like a question for -general or some other user-focused
mailing list, not hackers. At any rate, I don't see how 1e4 could just
be "ignored", but as Maciek points out, 1e4 and 10000 are of different
data types, which seems likely to be relevant somehow.

--
Robert Haas
EDB: http://www.enterprisedb.com

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#3)
Re: Exponential notation bug

Robert Haas <robertmhaas@gmail.com> writes:

This seems like a question for -general or some other user-focused
mailing list, not hackers. At any rate, I don't see how 1e4 could just
be "ignored", but as Maciek points out, 1e4 and 10000 are of different
data types, which seems likely to be relevant somehow.

I am also wondering about careless whitespace.

postgres=# select 9/1e1;
?column?
------------------------
0.90000000000000000000
(1 row)

postgres=# select 9/1 e1;
e1
----
9
(1 row)

In any case, I tried copying-and-pasting parts of the originally
mentioned query, and I saw nothing that looked like misbehavior.
Please show an exact, self-contained test case if you want us
to believe there's a bug here.

regards, tom lane

#5Marcos Pegoraro
marcos@f10.com.br
In reply to: Maciek Sakrejda (#2)
Re: Exponential notation bug

Em sex., 4 de abr. de 2025 às 13:13, Maciek Sakrejda <maciek@pganalyze.com>
escreveu:

maciek=# select pg_typeof(1e1)

Correct, this explains that

regards
Marcos