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.94.2) (envelope-from ) id 1vFxSk-004PEb-K6 for pgsql-general@arkaria.postgresql.org; Mon, 03 Nov 2025 16:31:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1vFxSi-005rt0-BD for pgsql-general@arkaria.postgresql.org; Mon, 03 Nov 2025 16:31:19 +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.94.2) (envelope-from ) id 1vFxSi-005rsr-0S for pgsql-general@lists.postgresql.org; Mon, 03 Nov 2025 16:31:19 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vFxSf-005F99-0R for pgsql-general@lists.postgresql.org; Mon, 03 Nov 2025 16:31:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5A3GVCt4329228; Mon, 3 Nov 2025 11:31:12 -0500 From: Tom Lane To: Marcelo Fernandes cc: pgsql-general@lists.postgresql.org Subject: Re: Increasing a NUMERIC column precision doesn't cause a table rewrite. Why? In-reply-to: References: Comments: In-reply-to Marcelo Fernandes message dated "Mon, 03 Nov 2025 21:24:00 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <329226.1762187472.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 03 Nov 2025 11:31:12 -0500 Message-ID: <329227.1762187472@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Marcelo Fernandes writes: > After doing some playing around with different operations against a nume= ric > column, namely: increasing/decreasing the precision or increasing/decrea= sing > the scale, I noticed that the table is rewritten in all cases except whe= n > increasing the precision number. Yup. > For example, is there a catalog table I can have a look to see how these= values > are defined, along with some form of documentation to understand how the= y are > interpreted by Postgres? You'd have to look into the source code: https://github.com/postgres/postgres/blob/c4067383cb2c155c4cfea2351036709e= 2ebb3535/src/backend/utils/adt/numeric.c The first few hundred lines of numeric.c are largely comments that you'd find relevant. Also see numeric_support(): https://github.com/postgres/postgres/blob/c4067383cb2c155c4cfea2351036709e= 2ebb3535/src/backend/utils/adt/numeric.c#L1179 ALTER TABLE skips table rewrite if the datatype conversion expression is simplified to a no-op by a support function such as numeric_support. regards, tom lane