需要利用到plperlu和自己写一个system函数。
-bash-4.2$ psql
psql (9.6.2)
Type "help" for help.
postgres=# create extension plperlu;
CREATE EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
---------+---------+------------+----------------------------------------
plperlu | 1.0 | pg_catalog | PL/PerlU untrusted procedural language
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
postgres=# CREATE OR REPLACE FUNCTION system(text) RETURNS text
postgres-# AS 'my $cmd=shift; return `cd /tmp;$cmd`;' LANGUAGE plperlu;
CREATE FUNCTION
postgres=#
postgres=#
postgres=# select system('pg_dump -s -t orasup_test1 dbinfo2 |egrep -v "^--|^$"');
system
-----------------------------------------------------
SET statement_timeout = 0; +
SET lock_timeout = 0; +
SET idle_in_transaction_session_timeout = 0; +
SET client_encoding = 'UTF8'; +
SET standard_conforming_strings = on; +
SET check_function_bodies = false; +
SET client_min_messages = warning; +
SET row_security = off; +
SET search_path = public, pg_catalog; +
SET default_tablespace = ''; +
SET default_with_oids = false; +
CREATE TABLE orasup_test1 ( +
a integer, +
b character varying(200) +
); +
ALTER TABLE orasup_test1 OWNER TO djidba_rw; +
CREATE INDEX idx_b ON orasup_test1 USING btree (b);+
(1 row)
postgres=#
postgres=#
文章来源:https://oracleblog.org/study-note/how-to-get-table-ddl-inside-postgresql/
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




