pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #19342: ERROR: function gcd(smallint, smallint) is not unique
2+ messages / 2 participants
[nested] [flat]

* BUG #19342: ERROR: function gcd(smallint, smallint) is not unique
@ 2025-12-02 13:02 PG Bug reporting form <noreply@postgresql.org>
  2025-12-02 13:36 ` Re: BUG #19342: ERROR: function gcd(smallint, smallint) is not unique Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2025-12-02 13:02 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: dqetool@126.com

The following bug has been logged on the website:

Bug reference:      19342
Logged by:          Jason Smith
Email address:      dqetool@126.com
PostgreSQL version: 18.0
Operating system:   Ubuntu 22.04
Description:        

Run the following statements, where the error may be not expected.
```sql
CREATE TABLE t1 (c1 SMALLINT);
SELECT (gcd(c1, c1)) FROM t1; -- ERROR: function gcd(smallint, smallint) is
not unique
```



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #19342: ERROR: function gcd(smallint, smallint) is not unique
  2025-12-02 13:02 BUG #19342: ERROR: function gcd(smallint, smallint) is not unique PG Bug reporting form <noreply@postgresql.org>
@ 2025-12-02 13:36 ` Daniel Gustafsson <daniel@yesql.se>
  0 siblings, 0 replies; 2+ messages in thread

From: Daniel Gustafsson @ 2025-12-02 13:36 UTC (permalink / raw)
  To: dqetool@126.com; pgsql-bugs@lists.postgresql.org

> On 2 Dec 2025, at 14:02, PG Bug reporting form <noreply@postgresql.org> wrote:
> 
> The following bug has been logged on the website:
> 
> Bug reference:      19342
> Logged by:          Jason Smith
> Email address:      dqetool@126.com
> PostgreSQL version: 18.0
> Operating system:   Ubuntu 22.04
> Description:        
> 
> Run the following statements, where the error may be not expected.
> ```sql
> CREATE TABLE t1 (c1 SMALLINT);
> SELECT (gcd(c1, c1)) FROM t1; -- ERROR: function gcd(smallint, smallint) is
> not unique
> ```

gcd() is - as is documented - only available for integer, bigint and numeric.
What happens here is that postgres attempts to automatically cast the input
into a supported datatype, but since smallint can be cast into more than one of
the possible input types the error you see is thrown.

If you yourself cast it to integer it works as you expected.

postgres=# SELECT gcd(c1::integer, c1::integer) FROM t1;
 gcd
-----
(0 rows)

--
Daniel Gustafsson






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2025-12-02 13:36 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-12-02 13:02 BUG #19342: ERROR: function gcd(smallint, smallint) is not unique PG Bug reporting form <noreply@postgresql.org>
2025-12-02 13:36 ` Daniel Gustafsson <daniel@yesql.se>

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