How to add constraints without validating data.
How to add constraints without validating data.
am 27.05.2010 14:25:56 von AmitKumar Jain
This is a multi-part message in MIME format.
--------------060509050208000206040209
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi Gurus
Is there any way in postgreSQL to apply constraints forcefully without
checking/validating Data ? It should validate only those records which
comes after constraints are applied.
I need this help as data is already loaded in database but "ALTER TABLE"
sql for adding CONSTRAINTS is taking enormous time.
Thanks for ideas/suggestion in Advance !!
--
Regards,
*Amit Jain*
*Synechron Technologies Pvt. Ltd.* 4th Floor, B Wing, Block 1.2, Embassy Techzone,
Rajiv Gandhi Infotech Park, Hinjewadi Phase II, Pune 411 057.
Phone : +91.20.40262000 Ext 2163 | Mobile:+91.9561298565 |VoIP : +1.732.415.0894
http://www.synechron.com MailTo: amitjain@synechron.com
--------------060509050208000206040209
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Hi Gurus
Is there any way in postgreSQL to apply constraints forcefully without
checking/validating Data ? It should validate only those records which
comes after constraints are applied.
I need this help as data is already loaded in database but "ALTER
TABLE" sql for adding CONSTRAINTS is taking enormous time.
Thanks for ideas/suggestion in Advance !!
--
style="font-size: 9pt;" size="2">Regards,
style="font-size: 11pt;" size="2">Amit Jain
style="font-size: 9pt;" size="2">Synechron Technologies Pvt. Ltd. 4th Floor, B Wing, Block 1.2, Embassy Techzone,
style="font-size: 9pt;" size="2">Rajiv Gandhi Infotech Park, Hinjewadi Phase II, Pune 411 057.
style="font-size: 9pt;" size="2">Phone : +91.20.40262000 Ext 2163 | Mobile:+91.9561298565 |
style="font-size: 9pt;" size="2">VoIP : +1.732.415.0894
style="font-size: 9pt;" size="2"> MailTo: amitjain
href="mailto:nilnandanj@synechron.com">@synechron.com
--------------060509050208000206040209--
Re: How to add constraints without validating data.
am 27.05.2010 14:34:35 von Nilesh Govindrajan
On Thu, May 27, 2010 at 5:55 PM, Amit jain wrote:
> Hi Gurus
>
> Is there any way in postgreSQL to apply constraints forcefully without
> checking/validating Data ? It should validate only those records which comes
> after constraints are applied.
>
> I need this help as data is already loaded in database but "ALTER TABLE" sql
> for adding CONSTRAINTS is taking enormous time.
>
> Thanks for ideas/suggestion in Advance !!
>
>
> --
>
> Regards,
>
> Amit Jain
> Synechron Technologies Pvt. Ltd. 4th Floor, B Wing, Block 1.2, Embassy
> Techzone,
> Rajiv Gandhi Infotech Park, Hinjewadi Phase II, Pune 411 057.
> Phone : +91.20.40262000 Ext 2163 | Mobile:+91.9561298565 | VoIP :
> +1.732.415.0894
> http://www.synechron.com MailTo: amitjain@synechron.com
>
>
I don't think there's any method to do that. If you add a constraint
using ALTER TABLE it will check existing data also. One option is you
create a new table with the constraints and same column names then:
insert into newtable values ( select * from oldtable)
but again this will check for old data, but may be faster.
--
Nilesh Govindarajan
Facebook: nilesh.gr
Twitter: nileshgr
Website: www.itech7.com
--
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Re: How to add constraints without validating data.
am 27.05.2010 18:00:54 von imartinez
--=-a+zbPXXLsbUI+qb0aPco
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
You have to disable triggers.
Two options:
- Export table data, truncate table (if your table is fk source you will
have a problem), add constraint and import exported data with
--disable-triggers flag in pg_restore.
- Perhaps you could add manually triger via pg_trigger table in
pg_catalog whith an insert into this table.
-----Original Message-----
From: Amit jain
To: pgsql-admin@postgresql.org
Subject: [ADMIN] How to add constraints without validating data.
Date: Thu, 27 May 2010 17:55:56 +0530
Hi Gurus
Is there any way in postgreSQL to apply constraints forcefully without
checking/validating Data ? It should validate only those records which
comes after constraints are applied.
I need this help as data is already loaded in database but "ALTER TABLE"
sql for adding CONSTRAINTS is taking enormous time.
Thanks for ideas/suggestion in Advance !!
--
Regards,
Amit Jain
Synechron Technologies Pvt. Ltd. 4th Floor, B Wing, Block 1.2, Embassy Techzone,
Rajiv Gandhi Infotech Park, Hinjewadi Phase II, Pune 411 057.
Phone : +91.20.40262000 Ext 2163 | Mobile:+91.9561298565 | VoIP : +1.732.415.0894
http://www.synechron.com MailTo: amitjain@synechron.com
--=-a+zbPXXLsbUI+qb0aPco
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit
You have to disable triggers.
Two options:
- Export table data, truncate table (if your table is fk source you will have a problem), add constraint and import exported data with --disable-triggers flag in pg_restore.
- Perhaps you could add manually triger via pg_trigger table in pg_catalog whith an insert into this table.
-----Original Message-----
From: Amit jain <>
To: pgsql-admin@postgresql.org <>
Subject: [ADMIN] How to add constraints without validating data.
Date: Thu, 27 May 2010 17:55:56 +0530
Hi Gurus
Is there any way in postgreSQL to apply constraints forcefully without checking/validating Data ? It should validate only those records which comes after constraints are applied.
I need this help as data is already loaded in database but "ALTER TABLE" sql for adding CONSTRAINTS is taking enormous time.
Thanks for ideas/suggestion in Advance !!
--
Regards,
Amit Jain
Synechron Technologies Pvt. Ltd. 4th Floor, B Wing, Block 1.2, Embassy Techzone,
Rajiv Gandhi Infotech Park, Hinjewadi Phase II, Pune 411 057.
Phone : +91.20.40262000 Ext 2163 | Mobile:+91.9561298565 | VoIP : +1.732.415.0894
--=-a+zbPXXLsbUI+qb0aPco--
Re: How to add constraints without validating data.
am 27.05.2010 18:15:25 von Nilesh Govindrajan
On Thu, May 27, 2010 at 9:30 PM, Iñigo Martinez Lasala
wrote:
> You have to disable triggers.
>
> Two options:
>
> - Export table data, truncate table (if your table is fk source you will
> have a problem), add constraint and import exported data with
> --disable-triggers flag in pg_restore.
>
> - Perhaps you could add manually triger via pg_trigger table in pg_catalog
> whith an insert into this table.
>
> -----Original Message-----
> From: Amit jain
> To: pgsql-admin@postgresql.org
> Subject: [ADMIN] How to add constraints without validating data.
> Date: Thu, 27 May 2010 17:55:56 +0530
>
> Hi Gurus
>
> Is there any way in postgreSQL to apply constraints forcefully without
> checking/validating Data ? It should validate only those records which co=
mes
> after constraints are applied.
>
> I need this help as data is already loaded in database but "ALTER TABLE" =
sql
> for adding CONSTRAINTS is taking enormous time.
>
> Thanks for ideas/suggestion in Advance !!
>
>
> --
>
> Regards,
>
> Amit Jain
> Synechron Technologies Pvt. Ltd. 4th Floor, B Wing, Block 1.2, Embassy
> Techzone,
> Rajiv Gandhi Infotech Park, Hinjewadi Phase II, Pune 411 057.
> Phone : +91.20.40262000 Ext 2163 | Mobile:+91.9561298565 | VoIP :
> +1.732.415.0894
> http://www.synechron.com MailTo: amitjain@synechron.com
>
>
>
>
>
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
Nilesh Govindarajan
Facebook: nilesh.gr
Twitter: nileshgr
Website: www.itech7.com
--=20
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Re: How to add constraints without validating data.
am 27.05.2010 18:19:49 von imartinez
--=-F0X791O7OdEgbw/aWyW+
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Constraints are special triggers, but triggers anyway.
So, If you truncate the table, create the contraint and then restore
with triggers disabled, it could be faster that create the contraint and
wait until it checks all table data... or not... :)
-----Original Message-----
From: Nilesh Govindarajan
To: Iñigo Martinez Lasala
Cc: Amit jain , pgsql-admin@postgresql.org
Subject: Re: [ADMIN] How to add constraints without validating data.
Date: Thu, 27 May 2010 21:45:25 +0530
How would disabling triggers help that ? He just wants to add
constraints without loss of data. I don't think he has any triggers.
--=-F0X791O7OdEgbw/aWyW+
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit
Constraints are special triggers, but triggers anyway.
So, If you truncate the table, create the contraint and then restore with triggers disabled, it could be faster that create the contraint and wait until it checks all table data... or not... :)
-----Original Message-----
From: Nilesh Govindarajan <>
To: Iñigo Martinez Lasala <>
Cc: Amit jain <
Subject: Re: [ADMIN] How to add constraints without validating data.
Date: Thu, 27 May 2010 21:45:25 +0530
How would disabling triggers help that ? He just wants to add
constraints without loss of data. I don't think he has any triggers.
--=-F0X791O7OdEgbw/aWyW+--
Re: How to add constraints without validating data.
am 27.05.2010 18:32:33 von Nilesh Govindrajan
On Thu, May 27, 2010 at 9:49 PM, Iñigo Martinez Lasala
wrote:
> Constraints are special triggers, but triggers anyway.
>
> So, If you truncate the table, create the contraint and then restore with
> triggers disabled, it could be faster that create the contraint and wait
> until it checks all table data... or not... :)
>
>
>
> -----Original Message-----
> From: Nilesh Govindarajan
> To: Iñigo Martinez Lasala
> Cc: Amit jain , pgsql-admin@postgresql.org
> Subject: Re: [ADMIN] How to add constraints without validating data.
> Date: Thu, 27 May 2010 21:45:25 +0530
>
> How would disabling triggers help that ? He just wants to add
> constraints without loss of data. I don't think he has any triggers.
>
>
>
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.
--=20
Nilesh Govindarajan
Facebook: nilesh.gr
Twitter: nileshgr
Website: www.itech7.com
--=20
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin
Re: How to add constraints without validating data.
am 28.05.2010 07:44:52 von Robert Voinea
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ñigo 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.
--=20
Robert Voinea
Software Developer
Phone: +40 21 408 38 00 / ext. 343
Fax: +40 21 408 38 08
Local time: GMT+2
http://www.topex.ro
--=20
Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-admin