How to generate the statement CREATE TABLE for an existing table in postgreSQL

0 votes
I have created a table in postgreSQL.

How to get the create table statement for a table that is already existing in Postgres via commandline or SQL statement?
Feb 9, 2022 in Database by Vaani
• 7,070 points
6,619 views

1 answer to this question.

0 votes

Generate table creation statement for an existing table
Use command line tool:

pg_dump -t 'schema_name.table_name' --schema-only database_name
 

Use TablePlus GUI Tool:

Select the table that you want to replicate from the list in the left sidebar.
Switch to the Structure tab at the bottom, or use shortcut keys Cmd + Ctrl + ]
Click on the Definition button on the top bar.
You will notice the table creation statement to copy.

pg_dump

pg_dump — extract a PostgreSQL database into a script file or other archive file

pg_dump [connection-option...] [option...] [dbname]

answered Feb 9, 2022 by Neha
• 9,020 points

Related Questions In Database

0 votes
2 answers
0 votes
2 answers

How to select the nth row in a SQL database table?

SELECT * FROM ( SELECT ID, NAME, ROW_NUMBER() ...READ MORE

answered Apr 23, 2020 in Database by anand
• 140 points
26,285 views
0 votes
1 answer

How to create an excel file in android?

In Android, create Excel XLSX or XLS ...READ MORE

answered Apr 4, 2022 in Database by Edureka
• 13,690 points
1,257 views
0 votes
0 answers
0 votes
2 answers

Install postgreSQL on Ubuntu

Follow the below commands to install PostgreSQL (PSQL) ...READ MORE

answered Nov 12, 2020 in Database by Prachi
• 140 points
1,273 views
0 votes
1 answer

Access progrs prompt without switching accounts

Use the following to get the postgres prompt ...READ MORE

answered Mar 22, 2019 in Database by Mahi
847 views
0 votes
1 answer

Create new role - postgresql on ubuntu

If you are logged in as the postgres account, ...READ MORE

answered Mar 22, 2019 in Database by Danny
962 views
0 votes
1 answer

How would I find the second largest salary from a employee table? [closed]

To find the 2nd largest salary from ...READ MORE

answered Feb 8, 2022 in Database by Vaani
• 7,070 points
926 views
0 votes
1 answer

How to rename a column in a database table using SQL?

For SQL Server, use sp_rename USE AdventureWorks; GO EXEC sp_rename 'Customers.CustomerTerritory.TerritoryID', ...READ MORE

answered Feb 9, 2022 in Database by Neha
• 9,020 points
762 views
+1 vote
1 answer

How to Insert date value in SQL table

Always use ANSI default string literal format for date i.e. YYYY-MM-DD like below. INSERT ...READ MORE

answered Feb 17, 2022 in Database by Neha
• 9,020 points
178,046 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP