Feature request: pg_get_tabledef(text)

From: Hans Schou <hans(dot)schou(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Feature request: pg_get_tabledef(text)
Date: 2023-11-22 15:41:24
Message-ID: CAApBw37LEQoFcDSWFmK_Xh=OfUVPeCqOxXn-sHBYYCbtsequLg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

Similar to pg_get_viewdef() and pg_get_functiondef() it would be useful
with a pg_get_tabledef() to get a full description of how a table is
defined.

Currently the table definition can be extracted with the command:

pg_dump -d foo --schema-only --table=bar | egrep '^[^-]'

The psql command '\d bar' gives some of the same information but it is not
in a format where it can be used to create a table.

Extra:
With the pg_get_tabledef() function in place it is very close to be
possible to implement pg_dump() within the system. So instead of running:
pg_dump -d foo
one could just run:
psql -d foo -c 'SELECT pg_dump()'

The function could also be called from within a programming language like
Java/PHP.

pg_dump has a lot of options where some of them could be parameters to the
pg_dump() function. If using a cloud or other webservice this will be an
easy way to make an extra backup.

--
π•³π–†π–“π–˜ π•Ύπ–ˆπ–π–”π–š
☏ ➁➁ βž…βžƒ βž‡β“ͺ ➁β“ͺ

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2023-11-22 15:50:57 Re: Feature request: pg_get_tabledef(text)
Previous Message Tom Lane 2023-11-22 14:59:07 Re: Removing oids with pg_repack