Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A6E96B5DBC8 for ; Fri, 17 Jun 2011 10:23:48 -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 18055-10 for ; Fri, 17 Jun 2011 13:23:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mimolette.dalibo.net (mimolette.dalibo.net [212.85.154.222]) by mail.postgresql.org (Postfix) with ESMTP id D8FC4B5DBC0 for ; Fri, 17 Jun 2011 10:23:41 -0300 (ADT) Received: from [192.168.0.12] (vbo91-5-88-186-16-24.fbx.proxad.net [88.186.16.24]) by mimolette.dalibo.net (Postfix) with ESMTPSA id 7F4006C2002; Fri, 17 Jun 2011 15:23:41 +0200 (CEST) Message-ID: <4DFB5560.4050804@dalibo.com> Date: Fri, 17 Jun 2011 15:23:44 +0200 From: Nicolas Thauvin User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110510 Icedove/3.1.10 MIME-Version: 1.0 To: Ibrahim Harrani CC: pgsql-admin@postgresql.org Subject: Re: pg_dump and drop table if exists statement References: In-Reply-To: X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/105 X-Sequence-Number: 37731 On 13/06/2011 09:56, Ibrahim Harrani wrote: > Hi, > > I am using PostgreSQL 9.0 I would like to dump some tables and all > functions,triggers on the database. > If I drop with pg_dump -c parameter, it removes public schema as > well. With -c, the drop of the public schema does not cascade, so the objects of the public schema that are not in the dump won't be deleted when restoring. > pg_dump -C parameter output has create table > but I can't restore this output directly(Because the tables are > already exist on the db) -C creates the database and connect to it inside the dump, it is different from -c. > There is no problem with functions. They have already this feature. > > How can backup/restore tables with DROP TABLE IF EXISTS statement like > in MySQL? without dropping all database and create again? Another way to do it is to use the custom format of pg_dump (-Fc), then pg_restore can be used with -c to first drop the objects to be restored. More, you can get pg_restore to echo the TOC with -l to a file, modify this file to choose what to restore, then run pg_restore again with -L /your/custom/list. PS: be careful with the -f option of pg_restore, if you don't know the tool -- Nicolas Thauvin DBA http://www.dalibo.com