Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGOvy-0004lT-Nw for pgsql-general@arkaria.postgresql.org; Tue, 16 Apr 2019 14:19:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hGOvx-0004ak-Ga for pgsql-general@arkaria.postgresql.org; Tue, 16 Apr 2019 14:19:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGOvx-0004ac-1R for pgsql-general@lists.postgresql.org; Tue, 16 Apr 2019 14:19:37 +0000 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGOvt-0005uM-MT for pgsql-general@lists.postgresql.org; Tue, 16 Apr 2019 14:19:35 +0000 Received: by mail-oi1-x243.google.com with SMTP id j132so17115866oib.2 for ; Tue, 16 Apr 2019 07:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=pwQBbhI893S3qWJ24U9LfQsCCZmpQ8SafS1yc/0mfMU=; b=i2fqb1ElUGd+YQ8G0AqUKsV351vKG9jH5hbH6WPloRM5eN9vgi7RYmALU9H4jIALTO n2vCYO6+5fWUHIlhk4WxUtFOiwSYnf/cICOc97RI8h4K7zH25sGxqBdFUNglkVMqBTX2 D124uGeVGsMylNmSujJEvzu4OUF/L+SidpN6DdRjolnmWe6jQWOjQccYKJZDMpXWNvf/ TrO28vpVkcSdq0JsVz790f0eiYXxJvbr4F9gxi3gSVBH2UvTkbx+vZ07zoyGY4FeMEPn 3JzjwTc42ZB3o6qM883ohLbcKM8OY5c2EKFE2iJmiNvKzc4Rv6ELY/BLekftSN6wz7WL Bosw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=pwQBbhI893S3qWJ24U9LfQsCCZmpQ8SafS1yc/0mfMU=; b=jr9ijOaT/GpVBYS5VJkY3x95HhBbhnttWDD/5+1a3+GvpYLGri/ut90S3ndgeuCFIr 8nYx/RZoe771HHgjN4qnzjCH5S6grukZTBuoQ6zVv7nFn9Aami9dDXaKOJb6v2mV1T+s 2Nu70pOEWEF4TBo/ynyjkTC9UqkFB6RDpDxmJKR3BuuovsQiMrUrbpzNgYNo8+EUBmGK IAoLW0Ei/Lnbg/Gjb9fbWBA0+4RW7ZnaSXqfuL+iy9XqqVwAODPRh0LiVBN2HKv6UQFf BpQVOT5qxfX915yPkhmS27KgCfV4iki5em3oJopKAUV4leo0FcYC3EK/buJbq6vyUbnN +DKA== X-Gm-Message-State: APjAAAUNFSb7qDl2KrL7/vdNaHB0MokimAJL6NO+yOEEpqv4LVBtyfsq 1qdjzQMpcUtFhfF0B4TgZTaS9llJpXE= X-Google-Smtp-Source: APXvYqzHvdZMJftAn2lhCGXub+lCNsEe8k5ipTRon5b4WeXpNC9HrfvJhnTGno5XhMdrelEzMPbK0w== X-Received: by 2002:aca:aa14:: with SMTP id t20mr22706139oie.166.1555424371055; Tue, 16 Apr 2019 07:19:31 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id 88sm22355620otj.3.2019.04.16.07.19.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Apr 2019 07:19:30 -0700 (PDT) Subject: Re: Alter domain type / avoiding table rewrite To: pgsql-general@lists.postgresql.org References: From: Ron Message-ID: <54c9d5ab-9be5-1499-1c36-f45ea33cc322@gmail.com> Date: Tue, 16 Apr 2019 09:19:29 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/16/19 4:22 AM, Tim Kane wrote: > So I have a situation where I would like to modify a field that is > currently a domain type over a varchar(9) > > Specifically: > CREATE DOMAIN old_type AS varchar(9) > > This isn't ideal, let's just say.. legacy. > > > I wish to modify this type.. ideally to a text type with a length > constraint.. or even just a slightly larger varchar(12) would suffice.. > > CREATE DOMAIN new_type AS text; > ALTER DOMAIN new_type ADD CONSTRAINT check_len CHECK ((length(VALUE) <= > 12)) NOT VALID; > > ALTER TABLE target ALTER > COLUMN value SET DATA TYPE new_type; > > > But it seems impossible to achieve either without a full table rewrite. But the column only has -- at most -- 9 characters of data in it. Won't the CHECK constraint instantly fail?  (ISTM that you should add the check constraint AFTER modifying the length and updating your data.) -- Angular momentum makes the world go 'round.