pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Drop all constraints 2+ messages / 2 participants [nested] [flat]
* Drop all constraints @ 2010-03-06 16:34 Gianvito Pio <pio.gianvito@gmail.com> 0 siblings, 1 reply; 2+ messages in thread From: Gianvito Pio @ 2010-03-06 16:34 UTC (permalink / raw) To: pgsql-sql Hi all, is there a way to drop all constraints of a table? I found this workaround in the manual: CREATE TABLE temp AS SELECT * FROM distributors; DROP TABLE distributors; CREATE TABLE distributors AS SELECT * FROM temp; DROP TABLE temp; Is there any other way to do it? Thanks ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Drop all constraints @ 2010-03-06 17:17 Andreas Kretschmer <akretschmer@spamfence.net> parent: Gianvito Pio <pio.gianvito@gmail.com> 0 siblings, 0 replies; 2+ messages in thread From: Andreas Kretschmer @ 2010-03-06 17:17 UTC (permalink / raw) To: pgsql-sql Gianvito Pio <pio.gianvito@gmail.com> wrote: > Hi all, > is there a way to drop all constraints of a table? > > I found this workaround in the manual: > > CREATE TABLE temp AS SELECT * FROM distributors; > DROP TABLE distributors; > CREATE TABLE distributors AS SELECT * FROM temp; > DROP TABLE temp; I think, you can change the table-name from temp to distributors: (alter table temp rename to distributors), it's cheaper. > > Is there any other way to do it? Maybe. I think you can walk through the system catalogs to find all constraints for a table and drop them (alter table foo drop constraint ...). I think, you should start with http://www.postgresql.org/docs/8.4/interactive/catalog-pg-constraint.html Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) "If I was god, I would recompile penguin with --enable-fly." (unknown) Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889° ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2010-03-06 17:17 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2010-03-06 16:34 Drop all constraints Gianvito Pio <pio.gianvito@gmail.com> 2010-03-06 17:17 ` Andreas Kretschmer <akretschmer@spamfence.net>
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