pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Alter domain type / avoiding table rewrite
Date: Tue, 16 Apr 2019 09:19:29 -0500
Message-ID: <54c9d5ab-9be5-1499-1c36-f45ea33cc322@gmail.com> (raw)
In-Reply-To: <CADVWZZKjhV9fLpewPdQMZx7V6kvGJViwMEDrPAv9m50rGeK9UA@mail.gmail.com>
References: <CADVWZZKjhV9fLpewPdQMZx7V6kvGJViwMEDrPAv9m50rGeK9UA@mail.gmail.com>

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.





view thread (16+ messages)  latest in thread

Message-ID: <54c9d5ab-9be5-1499-1c36-f45ea33cc322@gmail.com>
Permalink:  ../54c9d5ab-9be5-1499-1c36-f45ea33cc322@gmail.com/
Also on:    postgresql.org/message-id/54c9d5ab-9be5-1499-1c36-f45ea33cc322@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ronljohnsonjr@gmail.com
  Subject: Re: Alter domain type / avoiding table rewrite
  In-Reply-To: <54c9d5ab-9be5-1499-1c36-f45ea33cc322@gmail.com>
  References: <CADVWZZKjhV9fLpewPdQMZx7V6kvGJViwMEDrPAv9m50rGeK9UA@mail.gmail.com> <54c9d5ab-9be5-1499-1c36-f45ea33cc322@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox