Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wKblM-001B8q-2L for pgsql-bugs@arkaria.postgresql.org; Wed, 06 May 2026 12:54:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wKblL-00H0nf-2F for pgsql-bugs@arkaria.postgresql.org; Wed, 06 May 2026 12:54:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wKblL-00H0nW-1R for pgsql-bugs@lists.postgresql.org; Wed, 06 May 2026 12:54:03 +0000 Received: from mail-yx1-xb132.google.com ([2607:f8b0:4864:20::b132]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wKblI-00000000UN7-2B2U for pgsql-bugs@lists.postgresql.org; Wed, 06 May 2026 12:54:01 +0000 Received: by mail-yx1-xb132.google.com with SMTP id 956f58d0204a3-65c2cd216c9so5292949d50.3 for ; Wed, 06 May 2026 05:54:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778072040; cv=none; d=google.com; s=arc-20240605; b=jBMw2W3OVhwCxB78yLg2bWA+yWqXCIPhc1MSIM7bSUMQQbGvPjdqZYy/gP/PeRDM9J zoGzCaPvjBV8u1vdLyoziDfF9Raiu/PgPvNu/PPh2B7gXrP8BvKyPjZ1AKxIkaxyMoRF 6gCLgnJZjyYd3IQ2/YvdKImy6oUwZUeeNn7I0V8x8AVGlWI9S33DGXOCuYvYW/+ZlNEu UM0e4R4ajD2zMIuJ6IJjbFgiWLaLkknw25Lxqsxab2KTlp77yGxfRqgSiQwUVukBXOhK ScE4Md00Vxi67b33jc7ZuO7AEUX04Hizw+CAN9C7HUJFxRoJOoZjy2bRkItpxehvfQ/c uHfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:references:in-reply-to:mime-version :dkim-signature; bh=q/EVJXYlc9yiXJ5OoGJKKY58fJ9GMh7rHi0H5V+IDsc=; fh=yN3Q41LzLBGPNwaoLNzf+caVtNpzfn1MkPpnIDdUFAw=; b=SKYvpciXQTECNzGi7R+imp7VcWpzFEf44UaXWpekFNX9itmsxgbBA6j7tugGis/HvZ ++n1zfbpMziTC2NTjOZW0wwInaFKBWzfkxcRTAoJfsUWJ9k53GInNnfwkJUEO5ELimgr 1iYfB+d9Wc41EWp32qhI90+EJx74YvoedH67C1vQ9pRMDOg1/laT1yLdS5Zls9KN400i JrrazLyDPOrCcG9EYWJvNgR2Z97xc59y1y0QSOQqofWjndDGLvJEA4BRukFLwYy6bY5U W7gkCNu4h+CwpBulRldEzj7n2oK0tQozAlXrJ/RQKZ75qHGMA3GgV3TghoBb34DrZ8Cx 4Wpg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778072040; x=1778676840; darn=lists.postgresql.org; h=to:subject:message-id:date:from:references:in-reply-to:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=q/EVJXYlc9yiXJ5OoGJKKY58fJ9GMh7rHi0H5V+IDsc=; b=b/Ir74k21Bw+nsiPTwOvmXkk1O0wRub2mV5kWggaqZcXza3PRYq/v/x1p3VI/JbskV ABvkxXK7R8Wk6UDVqVDBB+e++V8oJ2HY+aWjh/V+On6okB4oujHCt+2OecUEBCTvTN/E Y9i7bIyh1YiJwWBIMmEQNkdYanBsZGPugN9GKS+s36MKgA6A1ab0FciI4HivDLAAFZ7+ YSd9HuP7aE+9RmthDzdbACAGcPUqEMy5qtfCKivooL7pXLQjv9DSGP52DDlM0gMeXuVZ WXVw+af/ZW/RexWGGoAqYkzZQyzLsfpQVPF2IJZWUe7sfs1poMbEfiFZeQdDk2G8/42G tQwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778072040; x=1778676840; h=to:subject:message-id:date:from:references:in-reply-to:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=q/EVJXYlc9yiXJ5OoGJKKY58fJ9GMh7rHi0H5V+IDsc=; b=X2m41Ajvg67/0dSs84oYRUYlRyajiFqBV7ci2UhQaRWlhzdbff4q8WdKW3gvahOFrC 3fTZQr+LeBkxbOYD8arHNZp1kfERVtX7O80O2e4aIq0qtj1HmUwERZgY9wMWETwPkiL7 Xc6WAyXafuOFp9yD0icTzxYgIsvxTnpdHx7Nb2aKpubmLc/tCFHfO+jPgwjkrBNt+cAn xqUGZFl2nszSTMBv5WiJQ0udCzeVrNBlp4B3w7r1uvsM63xec0vvRnwFEWtp2Dg3NGCL 7xK1CRSoP0u0VuuvdC1LEwux8AaEybH7aVHokaWVU5Pw3O3K6VFAKl4HJV0Pqg+PjJVA yJ/Q== X-Forwarded-Encrypted: i=1; AFNElJ/3RrlJhNRoi2NbCHJGo0mbhSBV8ETYJW1MR7KtAWpo1ho8DYAywx6r+jE6mLSStWYpKn9Q9Dq8wRbD@lists.postgresql.org X-Gm-Message-State: AOJu0YwSbFv7NUdsT9+7QdwvsGp/cngqgHtI2q043v5V3uOrFkNp4zuj G/olus2O5evszhZWK0ztgw3Z9nekTuYjRtWItlu6cZ5Yyv3iwEPzCXdJYk9hFrJOOpNgfWKpO8s zKV7cpf8K5Se4T57R3cbMfVaEeN3LnwzVsYLC X-Gm-Gg: AeBDievP2lkkwTn/8+P6Kxo3SF2G/EiztMTzlmWHpwE7pawDQjFmglNmI2xig89rLRx laxSeyQvugqcF3ptZiE9Z9WORUV2hqjJd0nH8v24GCN4zx2i3/04S2G2BGDWT+fFMMiSHdbvfYc eXXzBjnhT3tPdDOfeiUq0zmP2xuQjOhFxjlc/S1HD54qgiLFNn2ryNcfOE+chS2JFXC9Bdrxnon lW8SxPr1DyF1ENR90mbjlieep6de5oM5k/Z8XZI/7TODRoEHbZHF9OZfWWevRLVQuI8H2oHWl+6 exgu+muleo0OipXr X-Received: by 2002:a05:690e:24db:b0:65c:6220:5fcb with SMTP id 956f58d0204a3-65c799d5825mr2683609d50.50.1778072040316; Wed, 06 May 2026 05:54:00 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:7011:c14b:10b0:518:9db8:f75c with HTTP; Wed, 6 May 2026 05:53:58 -0700 (PDT) In-Reply-To: <19472-6b130bcff370911d@postgresql.org> References: <19472-6b130bcff370911d@postgresql.org> From: "David G. Johnston" Date: Wed, 6 May 2026 05:53:58 -0700 X-Gm-Features: AVHnY4I6qwFp79Uv2cE433UYVn7Kj0O3ymnNB_9gGh80ZHsH19VyZhmDTFl-3iI Message-ID: Subject: Re: BUG #19472: CAST(-32768::SMALLINT AS REAL) fails with "SMALLINT out of range" but -32768 is valid SMALLINT value To: "vectorplanck@gmail.com" , "pgsql-bugs@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000592490065125a86d" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000592490065125a86d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wednesday, May 6, 2026, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 19472 > Logged by: Pisces Mar. > Email address: vectorplanck@gmail.com > PostgreSQL version: 17.6 > Operating system: x86_64-windows > Description: > > Issue Description: > When casting -32768 to SMALLINT and then to REAL using the :: operator, > PostgreSQL throws an error "smallint out of range", even though -32768 is= a > valid value within the SMALLINT range (-32768 to +32767). > > Workaround: > Use parentheses: SELECT CAST((-32768) :: SMALLINT AS REAL); > Or use standard CAST syntax: SELECT CAST(-32768 AS SMALLINT); > These aren=E2=80=99t really workarounds; this is just how you need to write= the expression given our long-established and not going to change operator precedence and literal syntax parsing rules. David J. --000000000000592490065125a86d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wednesday, May 6, 2026, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:=C2=A0 =C2=A0 =C2=A0 19472
Logged by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Pisces Mar.
Email address:=C2=A0 =C2=A0 =C2=A0 vectorplanck@gmail.com
PostgreSQL version: 17.6
Operating system:=C2=A0 =C2=A0x86_64-windows
Description:=C2=A0 =C2=A0 =C2=A0 =C2=A0

Issue Description:
When casting -32768 to SMALLINT and then to REAL using the :: operator,
PostgreSQL throws an error "smallint out of range", even though -= 32768 is a
valid value within the SMALLINT range (-32768 to +32767).

Workaround:
Use parentheses: SELECT CAST((-32768) :: SMALLINT AS REAL);
Or use standard CAST syntax: SELECT CAST(-32768 AS SMALLINT);

These aren=E2=80=99t really workarounds; t= his is just how you need to write the expression given our long-established= and not going to change operator precedence and literal syntax parsing rul= es.

David J.

--000000000000592490065125a86d--