Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2010
    Posts
    40

    Unanswered: Copying the schema with tables

    I have a schema with several tables (all populated) that I want to copy into another table but without data. I also want to keep all constraints and indexes of table.
    What is the best way to do this?
    Thanks

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    I don't understand that question. You want to copy a schema with multiple tables into a single destination table?
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  3. #3
    Join Date
    Sep 2010
    Posts
    40
    I want to copy the content of the schema (tables) into some other schema but I don't want to copy the data in tables into new schema.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Something like:
    Code:
    pg_dump --schema-only --schema=source_schema --no-owner -f tables.sql your_db
    Then edit the file (tables.sql), change the SET search_path = ...; statement to list your target schema as the first schema and remove the source schema from it.
    Then run the SQL script in the target database using psql
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •