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 1s4hYk-000OUR-9U for pgsql-general@arkaria.postgresql.org; Wed, 08 May 2024 13:42:14 +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 1s4hYi-000sux-I2 for pgsql-general@arkaria.postgresql.org; Wed, 08 May 2024 13:42:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4hYi-000suo-69 for pgsql-general@lists.postgresql.org; Wed, 08 May 2024 13:42:12 +0000 Received: from mail-ua1-x930.google.com ([2607:f8b0:4864:20::930]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s4hYf-00020B-56 for pgsql-general@lists.postgresql.org; Wed, 08 May 2024 13:42:11 +0000 Received: by mail-ua1-x930.google.com with SMTP id a1e0cc1a2514c-7f3faea0ce0so1182266241.2 for ; Wed, 08 May 2024 06:42:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=starfishstorage.com; s=google; t=1715175728; x=1715780528; darn=lists.postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=X/pg6dlrhtiUMHoCuzKg4CLCWe3MUp8QmpSRr2vLHq8=; b=d7FVh5U8L9Gh8MsGCLdz2ejwI2zCbnAERXecUd/aB0KpDhtSkn+WG1hay2VZGhUGxO gOtcbJgzuVhcEqITEJzkiIQJ71Dpl+X/uJ2yj7mQ9Ov2oX1+mB1frnAXljlWeGCECVZG whyqrakb4W2iMS3/VhUzeMQiJ5IEBGHWPgtva0hHBGmBgqygbZ9wQq6Up1W6RQZdzRh+ tMMgEaikrDWtex7ByRQGpdc9/Yy7fGzxNZxH+lw8TGO9XgvH8puzwr3m7Tcje4mBVSHD vT+Vd8wXG73FUObNo3EX4FdbgS5Wr4OjjR/zaCrSAN6AGTjTtuJA6K7YFKFdyZ2ilHiC ausQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715175728; x=1715780528; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=X/pg6dlrhtiUMHoCuzKg4CLCWe3MUp8QmpSRr2vLHq8=; b=BpWDA/CSMMPKRGweZIHAdiyld4tEmglgzq/3d8R5zp9lzeiEf3/kBzkzSsM+w5VVYh kb19VtF/Sgm71sglKyiGBI2ie/bDCW3ZgG4SgRPqGM8n3uG/XNjRAvMOFmsFA0plzUuX 98f8saK00t47r1QCCia0EbMn1pemfdGondNhS1TfWVOy1mHwe+VEv0prHrNbscf4Tni0 Pf3She6FMd23/pxVS5bqcM5E3Dx4HjFdww0l6gr3hl0Ig1EnExubRYEXAK22EL8XrbmW B3CEEoIqHeW8iwUuAlCrl73CMhn7qkcc70BvjJkjRf1b28ZUUW82zbtjkl0lknDkB0OQ l3Iw== X-Gm-Message-State: AOJu0Yx78kcAk5eL9TnPL4b9o2K2yHzQSV5eP8gv0KBtMRyha8YnQ51Y uxrOrPchIJRfhoKPxWiBL2Bl6idPAyr5EMWpGG/FwLS0N35T4VZxi8zgjqLnLE+kCbIjljNg0WJ VjXnBCJ9UZDXRVkjv9CnKg9ImdsFfermlQ3ss7SGW9PK7BGl0mr+31w== X-Google-Smtp-Source: AGHT+IHLgHCqdJI5NrVjmVtQ/wQA9s1b0JCDl+t5ON+AuJEpRq0fQDJePCQzlOmZ7cE6Wy5xdF7filZABUJNad3Oduw= X-Received: by 2002:a05:6122:4690:b0:4d4:3fa5:e19e with SMTP id 71dfb90a1353d-4df69116325mr2649576e0c.2.1715175726470; Wed, 08 May 2024 06:42:06 -0700 (PDT) MIME-Version: 1.0 From: =?UTF-8?Q?Marcin_Barczy=C5=84ski?= Date: Wed, 8 May 2024 15:41:55 +0200 Message-ID: Subject: How to change NUMERIC type under a domain without rewriting a table? To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000e7741a0617f17758" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e7741a0617f17758 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello! In the following setup: DROP DOMAIN IF EXISTS uint64 CASCADE; DROP TABLE IF EXISTS demo; CREATE DOMAIN uint64 AS NUMERIC(20, 0); CREATE TABLE demo(key uint64); INSERT INTO demo SELECT g FROM generate_series(1, 10000000) g; I would like to change the type of "key" column to NUMERIC(40, 0). When I run, ALTER TABLE demo ALTER COLUMN key TYPE NUMERIC(40, 0); the whole table gets rewritten. Due to the table size it's not an option in my case. But, if there was no domain in the middle, and the column type was NUMERIC(20, 0), the command above would complete in-place without rewriting any rows. I attempted to modify the definition uint64 in pg_type table: UPDATE pg_type SET typtypmod =3D 2621444 WHERE typname =3D 'uint64'; It seems to work. Is it safe? Does it have any unintended consequences? Or maybe there is another way to achieve this? -- Marcin Barczy=C5=84ski --000000000000e7741a0617f17758 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello!

In the following setup:

DROP DOMAIN I= F EXISTS uint64 CASCADE;
DROP TABLE IF EXISTS demo;

CREATE DOMAIN= uint64 AS NUMERIC(20, 0);
CREATE TABLE demo(key uint64);
INSERT INTO= demo SELECT g FROM generate_series(1, 10000000) g;

I would like to = change the type of "key" column to NUMERIC(40, 0).
When I run,=

ALTER TABLE demo ALTER COLUMN key TYPE NUMERIC(40, 0);

the w= hole table gets rewritten. Due to the table size it's not an option in = my case.
But, if there was no domain in the middle, and the column type = was NUMERIC(20, 0), the command above would complete in-place without rewri= ting any rows.
I attempted to modify the definition uint64 in pg_type ta= ble:

UPDATE pg_type SET typtypmod =3D 2621444 WHERE typname =3D '= ;uint64';

It seems to work. Is it safe? Does it have any uninten= ded consequences?
Or maybe there is another way to achieve this?

= --
Marcin Barczy=C5=84ski
--000000000000e7741a0617f17758--