0

I need to play around with a data syncing program I wrote, but I want to copy the structure of the production database into a new table on my localhost Postgres database, without copying the data to my localhost db.

I was thinking along the lines of

CREATE TABLE new_table AS 
TABLE existing_table 
WITH NO DATA;

But I am unsure how to modify it to work with 2 different databases.

Any help would be appreciated

1 Answer 1

1

This boils down to the question "how to create the DDL script for a table" which can easily be done using pg_dump on the command line.

pg_dump -d some_db -h production_server -t existing_table --schema-only -f create.sql 

The file create.sql then contains the CREATE TABLE script that you can run on your local Postgres installation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.