Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate the "create table" sql statement for an existing table in postgreSQL

Tags:

postgresql

I have created a table in postgreSQL. I want to look at the SQL statement used to create the table but cannot figure it out.

How do I get the create table SQL statement for an existing table in Postgres via commandline or SQL statement?

like image 354
Raja Avatar asked Apr 07 '10 15:04

Raja


People also ask

How do you create a table statement from an existing table?

Question: How can I create a SQL table from another table without copying any values from the old table? Answer: To do this, the SQL CREATE TABLE syntax is: CREATE TABLE new_table AS (SELECT * FROM old_table WHERE 1=2);


1 Answers

pg_dump -t 'schema-name.table-name' --schema-only database-name 

More info - in the manual.

like image 112
Milen A. Radev Avatar answered Sep 30 '22 15:09

Milen A. Radev