pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: MichaelDBA <MichaelDBA@sqlexec.com>
To: richard coleman <rcoleman.ascentgl@gmail.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: PostgreSQL equivalents to dbms_metadata.get_ddl & dbms_metadata.get_dependent_ddl
Date: Sun, 19 Mar 2023 20:27:48 -0400
Message-ID: <978c008d-cad2-57e1-32ba-a7edcf4b1be9@sqlexec.com> (raw)
In-Reply-To: <CAGA3vBt=an4RqygEvUeeLPB_s0W92hC2DtjFmxV2eKu93NWOKA@mail.gmail.com>
References: <CAGA3vBt=an4RqygEvUeeLPB_s0W92hC2DtjFmxV2eKu93NWOKA@mail.gmail.com>

Use "psql -E" and then use the shortcut commands to get DDL stuff.  You 
will see the SQL used behind the scenes to get the stuff.

\d myschema.mytable
\df myschema.function
etc.

Regards,
Michael Vitale


richard coleman wrote on 3/19/2023 5:36 PM:
> Hello all,
> I am trying to find a simple way to get access the DDL information for 
> PostgreSQL tables, constraints, and indices via SQL.
>
> In Oracle there are the dbms_metadata.get_ddl() 
> and dbms_metadata.get_dependent_ddl() functions that you can call on 
> dual to get this information.
>
> EX:
> -- table DDL:
> select dbms_metadata.get_ddl('TABLE', 'MY_TABLE','MY_SCHEMA') as 
> "table_ddl" from dual;
>
> -- indices DDL
> select dbms_metadata.get_dependent_ddl('INDEX','MY_TABLE','MY_SCHEMA') 
> as "table_indicies" from dual;
>
> -- constraints DDL
> select 
> dbms_metadata.get_dependent_ddl('CONSTRAINT','MY_TABLE','MY_SCHEMA') 
> as "constraints_ddl" from dual;
>
> Is there an equivalent function to do the same in PostgreSQL?
>
> I know there are ways via pg_dump and psql, but what I need is a way 
> to do so via SQL.
>
> Thanks,
> rik.


Regards,

Michael Vitale

Michaeldba@sqlexec.com <mailto:michaelvitale@sqlexec.com>

703-600-9343

Attachments:

  [image/jpeg] pgadvanced3.jpg (20.6K, ../978c008d-cad2-57e1-32ba-a7edcf4b1be9@sqlexec.com/3-pgadvanced3.jpg)
  download | view image

view thread (20+ messages)  latest in thread

Message-ID: <978c008d-cad2-57e1-32ba-a7edcf4b1be9@sqlexec.com>
Permalink:  ../978c008d-cad2-57e1-32ba-a7edcf4b1be9@sqlexec.com/
Also on:    postgresql.org/message-id/978c008d-cad2-57e1-32ba-a7edcf4b1be9@sqlexec.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: MichaelDBA@sqlexec.com, rcoleman.ascentgl@gmail.com
  Subject: Re: PostgreSQL equivalents to dbms_metadata.get_ddl & dbms_metadata.get_dependent_ddl
  In-Reply-To: <978c008d-cad2-57e1-32ba-a7edcf4b1be9@sqlexec.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox