Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2259bf6

Browse files
committed
Fix dumping of casts and transforms using built-in functions
In pg_dump.c dumpCast() and dumpTransform(), we would happily ignore thecast or transform if it happened to use a built-in function because weweren't including the information about built-in functions when queryingpg_proc from getFuncs().Modify the query in getFuncs() to also gather information aboutfunctions which are used by user-defined casts and transforms (where"user-defined" means "has an OID >= FirstNormalObjectId"). This alsoadds to the TAP regression tests for 9.6 and master to cover thesetypes of objects.Back-patch all the way for casts, back to 9.5 for transforms.Discussion:https://www.postgresql.org/message-id/flat/20160504183952.GE10850%40tamriel.snowman.net
1 parent1999091 commit2259bf6

File tree

2 files changed

+90
-41
lines changed

2 files changed

+90
-41
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4711,8 +4711,11 @@ getFuncs(Archive *fout, int *numFuncs)
47114711
* 3. Otherwise, we normally exclude functions in pg_catalog. However, if
47124712
* they're members of extensions and we are in binary-upgrade mode then
47134713
* include them, since we want to dump extension members individually in
4714-
* that mode. Also, in 9.6 and up, include functions in pg_catalog if
4715-
* they have an ACL different from what's shown in pg_init_privs.
4714+
* that mode. Also, if they are used by casts or transforms then we need
4715+
* to gather the information about them, though they won't be dumped if
4716+
* they are built-in. Also, in 9.6 and up, include functions in
4717+
* pg_catalog if they have an ACL different from what's shown in
4718+
* pg_init_privs.
47164719
*/
47174720
if (fout->remoteVersion >= 90600)
47184721
{
@@ -4746,12 +4749,21 @@ getFuncs(Archive *fout, int *numFuncs)
47464749
"\n AND ("
47474750
"\n pronamespace != "
47484751
"(SELECT oid FROM pg_namespace "
4749-
"WHERE nspname = 'pg_catalog')",
4752+
"WHERE nspname = 'pg_catalog')"
4753+
"\n OR EXISTS (SELECT 1 FROM pg_cast"
4754+
"\n WHERE pg_cast.oid > %u "
4755+
"\n AND p.oid = pg_cast.castfunc)"
4756+
"\n OR EXISTS (SELECT 1 FROM pg_transform"
4757+
"\n WHERE pg_transform.oid > %u AND "
4758+
"\n (p.oid = pg_transform.trffromsql"
4759+
"\n OR p.oid = pg_transform.trftosql))",
47504760
acl_subquery->data,
47514761
racl_subquery->data,
47524762
initacl_subquery->data,
47534763
initracl_subquery->data,
4754-
username_subquery);
4764+
username_subquery,
4765+
g_last_builtin_oid,
4766+
g_last_builtin_oid);
47554767
if (dopt->binary_upgrade)
47564768
appendPQExpBufferStr(query,
47574769
"\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
@@ -4785,11 +4797,24 @@ getFuncs(Archive *fout, int *numFuncs)
47854797
"\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
47864798
"WHERE classid = 'pg_proc'::regclass AND "
47874799
"objid = p.oid AND deptype = 'i')");
4788-
appendPQExpBufferStr(query,
4800+
appendPQExpBuffer(query,
47894801
"\n AND ("
47904802
"\n pronamespace != "
47914803
"(SELECT oid FROM pg_namespace "
4792-
"WHERE nspname = 'pg_catalog')");
4804+
"WHERE nspname = 'pg_catalog')"
4805+
"\n OR EXISTS (SELECT 1 FROM pg_cast"
4806+
"\n WHERE pg_cast.oid > '%u'::oid"
4807+
"\n AND p.oid = pg_cast.castfunc)",
4808+
g_last_builtin_oid);
4809+
4810+
if (fout->remoteVersion >= 90500)
4811+
appendPQExpBuffer(query,
4812+
"\n OR EXISTS (SELECT 1 FROM pg_transform"
4813+
"\n WHERE pg_transform.oid > '%u'::oid"
4814+
"\n AND (p.oid = pg_transform.trffromsql"
4815+
"\n OR p.oid = pg_transform.trftosql))",
4816+
g_last_builtin_oid);
4817+
47934818
if (dopt->binary_upgrade && fout->remoteVersion >= 90100)
47944819
appendPQExpBufferStr(query,
47954820
"\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
@@ -10966,7 +10991,8 @@ dumpCast(Archive *fout, CastInfo *cast)
1096610991
{
1096710992
funcInfo = findFuncByOid(cast->castfunc);
1096810993
if (funcInfo == NULL)
10969-
return;
10994+
exit_horribly(NULL, "unable to find function definition for OID %u",
10995+
cast->castfunc);
1097010996
}
1097110997

1097210998
/*
@@ -11075,13 +11101,15 @@ dumpTransform(Archive *fout, TransformInfo *transform)
1107511101
{
1107611102
fromsqlFuncInfo = findFuncByOid(transform->trffromsql);
1107711103
if (fromsqlFuncInfo == NULL)
11078-
return;
11104+
exit_horribly(NULL, "unable to find function definition for OID %u",
11105+
transform->trffromsql);
1107911106
}
1108011107
if (OidIsValid(transform->trftosql))
1108111108
{
1108211109
tosqlFuncInfo = findFuncByOid(transform->trftosql);
1108311110
if (tosqlFuncInfo == NULL)
11084-
return;
11111+
exit_horribly(NULL, "unable to find function definition for OID %u",
11112+
transform->trftosql);
1108511113
}
1108611114

1108711115
/* Make sure we are in proper schema (needed for getFormattedTypeName) */

‎src/bin/pg_dump/t/002_pg_dump.pl

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,33 @@
11081108
section_post_data=> 1,
11091109
test_schema_plus_blobs=> 1, }, },
11101110

1111+
'CREATE CAST FOR timestamptz'=> {
1112+
create_order=> 51,
1113+
create_sql=>'CREATE CAST (timestamptz AS interval) WITH FUNCTION age(timestamptz) AS ASSIGNMENT;',
1114+
regexp=>qr/CREATE CAST\(timestamp with time zone AS interval\) WITH FUNCTION pg_catalog\.age\(timestamp with time zone\) AS ASSIGNMENT;/m,
1115+
like=> {
1116+
binary_upgrade=> 1,
1117+
clean=> 1,
1118+
clean_if_exists=> 1,
1119+
createdb=> 1,
1120+
defaults=> 1,
1121+
exclude_dump_test_schema=> 1,
1122+
exclude_test_table=> 1,
1123+
exclude_test_table_data=> 1,
1124+
no_blobs=> 1,
1125+
no_privs=> 1,
1126+
no_owner=> 1,
1127+
pg_dumpall_dbprivs=> 1,
1128+
schema_only=> 1,
1129+
section_pre_data=> 1,
1130+
},
1131+
unlike=> {
1132+
only_dump_test_schema=> 1,
1133+
only_dump_test_table=> 1,
1134+
pg_dumpall_globals=> 1,
1135+
section_post_data=> 1,
1136+
test_schema_plus_blobs=> 1, }, },
1137+
11111138
'CREATE DATABASE postgres'=> {
11121139
all_runs=> 1,
11131140
regexp=>qr/^
@@ -1856,38 +1883,32 @@
18561883
section_post_data => 1,
18571884
test_schema_plus_blobs => 1, }, },
18581885
1859-
#######################################
1860-
# Currently broken.
1861-
#######################################
1862-
#
1863-
#'CREATE TRANSFORM FOR int' => {
1864-
#create_order => 34,
1865-
#create_sql => 'CREATE TRANSFORM FOR int LANGUAGE SQL (FROM SQL WITH FUNCTION varchar_transform(internal), TO SQL WITH FUNCTION int4recv(internal));',
1866-
#regexp => qr/CREATE TRANSFORM FOR int LANGUAGE SQL\(FROM SQL WITH FUNCTION varchar_transform\(internal\), TO SQL WITH FUNCTION int4recv\(internal\)\);/m,
1867-
#like => {
1868-
#binary_upgrade => 1,
1869-
#clean => 1,
1870-
#clean_if_exists => 1,
1871-
#createdb => 1,
1872-
#defaults => 1,
1873-
#exclude_dump_test_schema => 1,
1874-
#exclude_test_table => 1,
1875-
#exclude_test_table_data => 1,
1876-
#no_blobs => 1,
1877-
#no_privs => 1,
1878-
#no_owner => 1,
1879-
#pg_dumpall_dbprivs => 1,
1880-
#schema_only => 1,
1881-
#section_post_data => 1,
1882-
#},
1883-
#unlike => {
1884-
#section_pre_data => 1,
1885-
#only_dump_test_schema => 1,
1886-
#only_dump_test_table => 1,
1887-
#pg_dumpall_globals => 1,
1888-
#test_schema_plus_blobs => 1,
1889-
#},
1890-
#},
1886+
'CREATE TRANSFORM FOR int' => {
1887+
create_order => 34,
1888+
create_sql => 'CREATE TRANSFORM FOR int LANGUAGE SQL (FROM SQL WITH FUNCTION varchar_transform(internal), TO SQL WITH FUNCTION int4recv(internal));',
1889+
regexp => qr/CREATE TRANSFORM FOR integer LANGUAGE sql\(FROM SQL WITH FUNCTION pg_catalog\.varchar_transform\(internal\), TO SQL WITH FUNCTION pg_catalog\.int4recv\(internal\)\);/m,
1890+
like => {
1891+
binary_upgrade => 1,
1892+
clean => 1,
1893+
clean_if_exists => 1,
1894+
createdb => 1,
1895+
defaults => 1,
1896+
exclude_dump_test_schema => 1,
1897+
exclude_test_table => 1,
1898+
exclude_test_table_data => 1,
1899+
no_blobs => 1,
1900+
no_privs => 1,
1901+
no_owner => 1,
1902+
pg_dumpall_dbprivs => 1,
1903+
schema_only => 1,
1904+
section_pre_data => 1,
1905+
},
1906+
unlike => {
1907+
only_dump_test_schema => 1,
1908+
only_dump_test_table => 1,
1909+
pg_dumpall_globals => 1,
1910+
section_post_data => 1,
1911+
test_schema_plus_blobs => 1, }, },
18911912
18921913
'CREATE LANGUAGE pltestlang' => {
18931914
all_runs => 1,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp