Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions doc/src/sgml/func/func-info.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -3845,4 +3845,90 @@ acl | {postgres=arwdDxtm/postgres,foo=r/postgres}

</sect2>

<sect2 id="functions-get-object-ddl">
<title>Get Object DDL Functions</title>

<para>
The functions described in <xref linkend="functions-get-object-ddl-table"/>
return the Data Definition Language (DDL) statement for any given database object.
This feature is implemented as a set of distinct functions for each object type.
</para>

<table id="functions-get-object-ddl-table">
<title>Get Object DDL Functions</title>
<tgroup cols="1">
<thead>
<row>
<entry role="func_table_entry"><para role="func_signature">
Function
</para>
<para>
Description
</para></entry>
</row>
</thead>

<tbody>
<row>
<entry role="func_table_entry"><para role="func_signature">
<indexterm>
<primary>pg_get_database_ddl</primary>
</indexterm>
<function>pg_get_database_ddl</function>
( <parameter>database_id</parameter> <type>regdatabase</type>
<optional>, <literal>VARIADIC</literal> <parameter>options</parameter>
<type>"any"</type> </optional> )
<returnvalue>text</returnvalue>
</para>
<para>
Reconstructs the <command>CREATE DATABASE</command> statement from the
system catalogs for a specified database by name or OID. The optional
variadic arguments are name/value pairs to control the output
formatting and content (e.g., <literal>'pretty', true, 'owner', false</literal>).
Supported options are explained below.
</para></entry>
</row>
</tbody>
</tgroup>
</table>

<para>
The <parameter>options</parameter> for <function>pg_get_database_ddl</function>
provide fine-grained control over the generated SQL. Options are passed as
alternating key/value pairs where the key is a text string and the
value is either a boolean or a text string representing a boolean
(<literal>true</literal>, <literal>false</literal>, <literal>yes</literal>,
<literal>no</literal>, <literal>1</literal>, <literal>0</literal>,
<literal>on</literal>, <literal>off</literal>):
<itemizedlist>
<listitem>
<para>
<literal>'pretty', true</literal> (or <literal>'pretty', 'yes'</literal>):
Adds newlines and indentation for better readability.
</para>
</listitem>
<listitem>
<para>
<literal>'owner', false</literal> (or <literal>'owner', 'no'</literal>):
Omits the <literal>OWNER</literal> clause from the reconstructed statement.
</para>
</listitem>
<listitem>
<para>
<literal>'tablespace', false</literal> (or <literal>'tablespace', '0'</literal>):
Omits the <literal>TABLESPACE</literal> clause from the reconstructed statement.
</para>
</listitem>
<listitem>
<para>
<literal>'defaults', true</literal> (or <literal>'defaults', '1'</literal>):
Includes clauses for parameters that are currently at their default values
(e.g., <literal>CONNECTION LIMIT -1</literal>), which are normally omitted for brevity.
</para>
</listitem>
</itemizedlist>
</para>

</sect2>

</sect1>
6 changes: 6 additions & 0 deletions src/backend/catalog/system_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,12 @@ BEGIN ATOMIC
END;


CREATE OR REPLACE FUNCTION
pg_get_database_ddl(database_id regdatabase, VARIADIC options "any" DEFAULT NULL)
RETURNS text
LANGUAGE internal
AS 'pg_get_database_ddl';

--
-- The default permissions for functions mean that anyone can execute them.
-- A number of functions shouldn't be executable by just anyone, but rather
Expand Down
Loading