Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9cf2b85

Browse files
committed
Fix underqualified cast-target type names in pg_dump and psql queries.
Queries running with some non-pg_catalog schema frontmost in their search path need to be careful to schema-qualify type names that should be sought in pg_catalog. Vitaly Burovoy reported an oversight of this sort in pg_dump's dumpSequence, and grepping detected another one in psql's describeOneTableDetails, both introduced by sequence-related changes in v10. In pg_dump, we can fix things by removing the cast altogether, since it doesn't really matter what data types are reported for these query result columns. Likewise in psql, the query seemed to be working unduly hard to get a result that's guaranteed to be exactly 'bigint'. I also changed a couple of occurrences of "::char" similarly. These are not bugs, since "char" is a typename keyword and not subject to search_path rules, but it seems better to use uniform style. Vitaly Burovoy and Tom Lane Discussion: https://postgr.es/m/CAKOSWN=ds66zLw2SqkLTM8wbXFgDbc_OdkmT3dJfPT2mE5kipA@mail.gmail.com
1 parent 7becb5f commit 9cf2b85

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13044,7 +13044,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo)
1304413044
collinfo->dobj.catId.oid);
1304513045
else
1304613046
appendPQExpBuffer(query, "SELECT "
13047-
"'c'::char AS collprovider, "
13047+
"'c' AS collprovider, "
1304813048
"collcollate, "
1304913049
"collctype, "
1305013050
"NULL AS collversion "
@@ -16351,13 +16351,16 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1635116351
/*
1635216352
* Before PostgreSQL 10, sequence metadata is in the sequence itself,
1635316353
* so switch to the sequence's schema instead of pg_catalog.
16354+
*
16355+
* Note: it might seem that 'bigint' potentially needs to be
16356+
* schema-qualified, but actually that's a keyword.
1635416357
*/
1635516358

1635616359
/* Make sure we are in proper schema */
1635716360
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
1635816361

1635916362
appendPQExpBuffer(query,
16360-
"SELECT 'bigint'::name AS sequence_type, "
16363+
"SELECT 'bigint' AS sequence_type, "
1636116364
"start_value, increment_by, max_value, min_value, "
1636216365
"cache_value, is_cycled FROM %s",
1636316366
fmtId(tbinfo->dobj.name));
@@ -16368,7 +16371,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
1636816371
selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
1636916372

1637016373
appendPQExpBuffer(query,
16371-
"SELECT 'bigint'::name AS sequence_type, "
16374+
"SELECT 'bigint' AS sequence_type, "
1637216375
"0 AS start_value, increment_by, max_value, min_value, "
1637316376
"cache_value, is_cycled FROM %s",
1637416377
fmtId(tbinfo->dobj.name));

src/bin/psql/describe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ describeOneTableDetails(const char *schemaname,
15961596
else
15971597
{
15981598
printfPQExpBuffer(&buf,
1599-
"SELECT pg_catalog.format_type('bigint'::regtype, NULL) AS \"%s\",\n"
1599+
"SELECT 'bigint' AS \"%s\",\n"
16001600
" start_value AS \"%s\",\n"
16011601
" min_value AS \"%s\",\n"
16021602
" max_value AS \"%s\",\n"
@@ -2483,7 +2483,7 @@ describeOneTableDetails(const char *schemaname,
24832483
{
24842484
printfPQExpBuffer(&buf,
24852485
"SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2486-
"'O'::char AS ev_enabled\n"
2486+
"'O' AS ev_enabled\n"
24872487
"FROM pg_catalog.pg_rewrite r\n"
24882488
"WHERE r.ev_class = '%s' ORDER BY 1;",
24892489
oid);

0 commit comments

Comments
 (0)