Re: Alter domain type / avoiding table rewrite

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Alter domain type / avoiding table rewrite
Date: 2019-04-16 14:19:29
Message-ID: 54c9d5ab-9be5-1499-1c36-f45ea33cc322@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2019-04-16 14:28:16 Re: Alter domain type / avoiding table rewrite
Previous Message Adrian Klaver 2019-04-16 14:17:58 Re: Alter domain type / avoiding table rewrite