函数pg_get_tabledef()支持显示全局临时表的DDL

This commit is contained in:
douxin 2020-12-30 14:52:58 +08:00 committed by zhaowenhao
parent 482df78c44
commit 1dc22834b1
4 changed files with 36 additions and 3 deletions

View File

@ -2171,8 +2171,12 @@ static char* pg_get_tabledef_worker(Oid tableoid)
appendStringInfo(&buf, "SET search_path = %s;", quote_identifier(get_namespace_name(tableinfo.spcid)));
appendStringInfo(&buf, "\nCREATE %s %s %s",
(tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED) ? "UNLOGGED" : "", reltypename, relname);
appendStringInfo(&buf,
"\nCREATE %s%s %s",
(table_info.relpersistence == RELPERSISTENCE_UNLOGGED) ? "UNLOGGED " :
((table_info.relpersistence == RELPERSISTENCE_GLOBAL_TEMP) ? "GLOBAL TEMPORARY " : ""),
rel_type_name,
rel_name);
// get attribute info
actual_atts = get_table_attribute(tableoid, &buf, formatter, ft_frmt_clmn, cnt_ft_frmt_clmns);

View File

@ -0,0 +1,20 @@
CREATE GLOBAL TEMPORARY TABLE gtt1 (
ID INTEGER NOT NULL,
NAME CHAR(16) NOT NULL,
ADDRESS VARCHAR(50),
POSTCODE CHAR(6)
)
ON COMMIT PRESERVE ROWS;
select * from pg_get_tabledef('gtt1');
pg_get_tabledef
----------------------------------------------------------------------
SET search_path = public; +
CREATE GLOBAL TEMPORARY TABLE gtt1 ( +
id integer NOT NULL, +
name character(16) NOT NULL, +
address character varying(50), +
postcode character(6) +
) +
WITH (orientation=row, compression=no, on_commit_delete_rows=false);
(1 row)

View File

@ -1,4 +1,4 @@
# ----------
# ----------
# The first group of parallel tests
# ----------
test: boolean char name varchar text int2 int4 int8 oid float4 float8 bit numeric numeric_2 txid uuid money
@ -85,3 +85,4 @@
test: enum_empty_test
test: alarm_component_test
test: unify_definition_superuser
test: global_temporary_table_get_table_def

View File

@ -0,0 +1,8 @@
CREATE GLOBAL TEMPORARY TABLE gtt1 (
ID INTEGER NOT NULL,
NAME CHAR(16) NOT NULL,
ADDRESS VARCHAR(50),
POSTCODE CHAR(6)
)
ON COMMIT PRESERVE ROWS;
select * from pg_get_tabledef('gtt1');