pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_dump and drop table if exists statement
2+ messages / 2 participants
[nested] [flat]

* pg_dump and drop table if exists statement
@ 2011-06-13 07:56 Ibrahim Harrani <ibrahim.harrani@gmail.com>
  2011-06-17 13:23 ` Re: pg_dump and drop table if exists statement Nicolas Thauvin <nicolas.thauvin@dalibo.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Ibrahim Harrani @ 2011-06-13 07:56 UTC (permalink / raw)
  To: pgsql-admin

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.  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)
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?

Thanks in advance.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: pg_dump and drop table if exists statement
  2011-06-13 07:56 pg_dump and drop table if exists statement Ibrahim Harrani <ibrahim.harrani@gmail.com>
@ 2011-06-17 13:23 ` Nicolas Thauvin <nicolas.thauvin@dalibo.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Nicolas Thauvin @ 2011-06-17 13:23 UTC (permalink / raw)
  To: Ibrahim Harrani <ibrahim.harrani@gmail.com>; +Cc: pgsql-admin



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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-06-17 13:23 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-06-13 07:56 pg_dump and drop table if exists statement Ibrahim Harrani <ibrahim.harrani@gmail.com>
2011-06-17 13:23 ` Nicolas Thauvin <nicolas.thauvin@dalibo.com>

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