I want to get DDL of a table in PostgreSQL that looks like this:
CREATE TABLE public.person (
id serial NOT NULL,
"name" varchar(50) NOT NULL,
age int4 NOT NULL,
CONSTRAINT person_name_uk UNIQUE (name),
CONSTRAINT person_pkey PRIMARY KEY (id)
);
I remember, in MySQL there is a query SHOW CREATE TABLE
. Is there a similar way to get the same in PostgreSQL?
I am interested in solution for the version PostgreSQL 12.
I need a solution exactly in SQL, so I could use inside of SQL functions. Thus the pg_dump
of \d+
don't fit.