Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 82A1A632B8E for ; Fri, 28 May 2010 03:00:05 -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 63991-08 for ; Fri, 28 May 2010 05:59:57 +0000 (UTC) X-Greylist: delayed 00:14:58.625008 by SQLgrey-1.7.6 Received: from mail2.topex.ro (mail2.topex.ro [82.137.49.134]) by mail.postgresql.org (Postfix) with ESMTP id 16924632B59 for ; Fri, 28 May 2010 02:59:56 -0300 (ADT) Received: from mail2.topex.ro ([172.27.168.99]) by topex.ro with MailEnable ESMTP; Fri, 28 May 2010 08:45:02 +0300 X-ASG-Debug-ID: 1275025494-039a64d50001-ysJW5H Received: from vr.localnet (89-38-174-194.volio.ro [89.38.174.194]) by mail2.topex.ro with ESMTP id zggey9KdyFyKZNyx; Fri, 28 May 2010 08:44:54 +0300 (EEST) X-Barracuda-Envelope-From: robert.voinea@topex.ro X-Barracuda-AUTH-User: robert.voinea X-Barracuda-AUTH-User: robert.voinea X-Barracuda-AUTH-User: robert.voinea X-Barracuda-AUTH-User: robert.voinea X-ASG-Whitelist: Client From: Robert Voinea Organization: Topex To: pgsql-admin@postgresql.org X-ASG-Orig-Subj: Re: [ADMIN] How to add constraints without validating data. Subject: Re: How to add constraints without validating data. Date: Fri, 28 May 2010 08:44:52 +0300 User-Agent: KMail/1.13.2 (Linux/2.6.32-22-generic; KDE/4.4.2; i686; ; ) Cc: Nilesh Govindarajan , =?utf-8?q?I=C3=B1igo_Martinez_Lasala?= , Amit jain References: <4BFE64D4.4020107@synechron.com> <1274977189.19383.51.camel@deimos> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <201005280844.53208.robert.voinea@topex.ro> X-Barracuda-Connect: 89-38-174-194.volio.ro[89.38.174.194] X-Barracuda-Start-Time: 1275025494 X-Barracuda-URL: http://172.27.168.99:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at topex.ro X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.907 tagged_above=-10 required=5 tests=BAYES_50=0.8, RCVD_IN_BL_SPAMCOP_NET=1.347, RCVD_IN_SORBS_WEB=0.77, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: ** X-Archive-Number: 201005/275 X-Sequence-Number: 34748 Why don't you use a partition? Create another table that inherits from the table and add your new constrai= nts=20 to the new table. On Thursday 27 May 2010 19:32:33 Nilesh Govindarajan wrote: > On Thu, May 27, 2010 at 9:49 PM, I=C3=B1igo Martinez Lasala >=20 > wrote: > > Constraints are special triggers, but triggers anyway. > >=20 > > So, If you truncate the table, create the contraint and then restore wi= th > > triggers disabled, it could be faster that create the contraint and wait > > until it checks all table data... or not... :) > >=20 > > How would disabling triggers help that ? He just wants to add > > constraints without loss of data. I don't think he has any triggers. >=20 > I agree constraints are triggers. But as far as I know, truncating > table doesn't disable the constraints. > Its same as deleteing all rows and then altering the table. > In that manner, even my solution would be appropriate because it > creates a duplicate table with the constraints. > Whatever be the method, I don't think its possible to avoid the > constraints. Correct me if I'm wrong. =2D-=20 Robert Voinea Software Developer Phone: +40 21 408 38 00 / ext. 343 =46ax: +40 21 408 38 08 Local time: GMT+2 http://www.topex.ro