BUG #18977: Unexpected result of function to_char

PG Bug reporting form <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 798604270@qq.com
Date: 2025-07-03T13:23:12Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      18977
Logged by:          Chi Zhang
Email address:      798604270@qq.com
PostgreSQL version: 18beta1
Operating system:   ubuntu 24.04 with docker
Description:        

hi,
the following two queries are equivalent but return different results:
```
SELECT ((to_char(-1E30, '0.9930824')));
  to_char
------------
 -#.##3#824
(1 row)
PREPARE prepare_query (float8) AS SELECT ((to_char($1, '0.9930824')));
EXECUTE prepare_query(-1E30::float8);
 to_char
---------
 -#.
```
furthermore, it seems the second argument of to_chat is formatted, but
according to the document in
https://www.postgresql.org/docs/current/functions-formatting.html, it should
be the first argument to be formatted