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 1tX5NS-003nOB-9v for pgsql-general@arkaria.postgresql.org; Sun, 12 Jan 2025 21:20:10 +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 1tX5NP-002yrl-Ii for pgsql-general@arkaria.postgresql.org; Sun, 12 Jan 2025 21:20:08 +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 1tX5NP-002yrd-7k for pgsql-general@lists.postgresql.org; Sun, 12 Jan 2025 21:20:07 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tX5NN-00040R-0c for pgsql-general@lists.postgresql.org; Sun, 12 Jan 2025 21:20:06 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 772E71AA8F; Sun, 12 Jan 2025 22:19:01 +0100 (CET) Date: Sun, 12 Jan 2025 22:19:01 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Alter table fast Message-ID: <20250112211901.r6cealpdlsovwahv@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <9e3d705e-df1d-4d32-b5ba-718f492cb1cc@gmx.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="orphskff6jvjqidf" Content-Disposition: inline In-Reply-To: <9e3d705e-df1d-4d32-b5ba-718f492cb1cc@gmx.net> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --orphskff6jvjqidf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2025-01-09 20:52:27 +0100, shammat@gmx.net wrote: > Am 09.01.25 um 20:17 schrieb veem v: > > > Out of curiosity, why NUMERIC(15,0) instead of BIGINT? > >=20 > > It's for aligning the database column types to the data model and > > it's happening across all the upstream downstream systems. I was > > thinking if this can be made faster with the single line alter > > statement "Alter table alter column type > > numeric(15,0) USING ::NUMERIC(15,0);" >=20 > Hmm, I would rather change numeric(15,0) to bigint if I had to "align" ty= pes across systems. I'm also wondering what "the data model" is. If I have numeric(15,0) in an abstract data model, that means that I expect values larger than 99,999,999,999,999 but at most 999,999,999,999,999. That seems to be oddly specific and also somewhat at odds with reality when until now there apparently haven't been any values larger than 2,147,483,647. What kind of real world value could suddenly jump by more than 5 orders of magnitude but certainly not by 7? A bigint is much less precise (more than 2,147,483,647 but not more than 9,223,372,036,854,775,807) and therefore more suitable for values where you don't really know the range. However, for the problem at hand, I doubt it makes any difference. Surely converting a few million values takes much less time than rewriting a 50 GB table and all its indexes. So there isn't really a faster way to do what Veem wants. There may however be less disruptive way: He could create a new column with the new values (which takes at least as long but can be done in the background) and then switch it over and drop the old column. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --orphskff6jvjqidf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmeEMb8ACgkQ8g5IURL+ KF3J3RAAqqlLN4eXwXJ9gDO9x5DP3QQFMCuPGi4FQYKKfcd5FvfDQto9cNLHxUZK f45yHblgvuOfzfJcUczz5+O2pHEqMH+nJy6Tddoyt8dz/mFTTNISpg/jrj7U0UMK aFU9XHQxlBMK39gmr0tjTSM6IREEAYIad7J9zg1hhWE2QHqZQHJfhcfzkza4meyx JrIFlNHneK72NJmbtXEDOIjWoB7mGbp17mekyr0TO23ARAatu3by80RzMuftMplJ 4m8sbbYloARW2IInHfihAv+tirmiQGpHHmXwwDjYBqUZWKUK2/45o7ms6LmlXEKr CAVHpimMPiThdlVHvifmCQVhMD49xcx/YPnFOWyHinRGeXIEy/WJXdQyTTZqQqxm OUhyWt4qAY5r6ZKy98p+HocgRXG/7xox4CFpPdQOUYX7T6W9470EC4wJ6Y//+wUb S1kyz0v0HvxxdPA3xRbahcv7V+G0XTGRYigokgz1LV1CGkMWt4CvcC9Qf0O3oWVB HZmallAQLrCOXGNe1hZRfEXVkANb7LU3edDgNRp+PlU9UqQGus3wSEegaR7ZrkRu WKkbVC1I/K1qlkz6wuzgkAY8HcnC5nwD2qSgopAWNFEGeE7nkFbtZxCxNbKSvJxF aZYora53rhHl6WY+/RHO/35bFngymdlDLVWzv2oy1/GDvr9Ea1w= =sCvz -----END PGP SIGNATURE----- --orphskff6jvjqidf--