Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 6F798633327 for ; Thu, 8 Jul 2010 12:10:52 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 30330-09-2 for ; Thu, 8 Jul 2010 15:10:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og109.obsmtp.com (exprod7og109.obsmtp.com [64.18.2.171]) by mail.postgresql.org (Postfix) with SMTP id D9B2D6321BB for ; Thu, 8 Jul 2010 12:10:42 -0300 (ADT) Received: from source ([209.85.160.42]) by exprod7ob109.postini.com ([64.18.6.12]) with SMTP ID DSNKTDXqcWAwVK2FKEWgkvJmCHX1SmMuPxfH@postini.com; Thu, 08 Jul 2010 08:10:43 PDT Received: by pwi1 with SMTP id 1so390078pwi.1 for ; Thu, 08 Jul 2010 08:10:41 -0700 (PDT) Received: by 10.142.178.2 with SMTP id a2mr3914653wff.310.1278601840806; Thu, 08 Jul 2010 08:10:40 -0700 (PDT) Received: from Vibhor-Kumars-MacBook-Pro.local ([121.241.184.130]) by mx.google.com with ESMTPS id c26sm8620256rvf.15.2010.07.08.08.10.34 (version=SSLv3 cipher=RC4-MD5); Thu, 08 Jul 2010 08:10:36 -0700 (PDT) Message-ID: <4C3629D9.9000900@enterprisedb.com> Date: Thu, 08 Jul 2010 20:41:13 +0100 From: Vibhor Kumar Organization: EnterpriseDB Corporation User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.10) Gecko/20100512 Lightning/1.0b1 Thunderbird/3.0.5 MIME-Version: 1.0 To: Dmitriy Igrishin CC: postgres list Subject: Re: Question about domains. References: In-Reply-To: Content-Type: text/plain; charset=windows-1250; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.173 tagged_above=-5 required=5 tests=BAYES_00=-1.9, DATE_IN_FUTURE_03_06=3.027, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201007/48 X-Sequence-Number: 34361 On 08/07/10 2:27 PM, Dmitriy Igrishin wrote: > Hey all, > > Is there a way to add constraint to the domain that used by a composite type > that used by a table? E.g.: Currently in PG, adding constraint on Domain, which is already in use is not supported. > CREATE DOMAIN superid AS integer; > > CREATE TYPE idtype AS > ( > id superid > ); > > CREATE TABLE mytab (id idtype NOT NULL); > > ALTER DOMAIN superid ADD CONSTRAINT superid_check CHECK (VALUE > 0); > > ALTER DOMAIN superid DROP CONSTRAINT superid_check; > > produces the following output: > > dmitigr=> CREATE DOMAIN > Time: 23,809 ms > dmitigr=> CREATE TYPE > Time: 44,875 ms > dmitigr=> CREATE TABLE > Time: 134,101 ms > dmitigr=> ERROR: cannot alter type "superid" because column > "mytab"."id" uses it > dmitigr=> ALTER DOMAIN > Time: 0,270 ms > > As you can see, adding constraint to the domain produces an error, while > dropping > constraint is possible! > Any comments? If you want, you can try following: CREATE DOMAIN superid1 AS integer check(value > 0); create type idtype1 as (id superid1); create or replace function idtype2idtype1(idtype) returns idtype1 as $$ select row($1.id)::idtype1; $$ language sql; create cast (idtype as idtype1) with function idtype2int(idtype) as implicit; Then execute the alter table command to convert the data type: alter table mytab alter column id type idtype1; -- Thanks& Regards, Vibhor Kumar. EnterpriseDB Corporation The Enterprise Postgres Company