Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix underqualified cast-target type names in pg_dump and psql queries.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 31 Oct 2017 17:40:23 +0000 (13:40 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 31 Oct 2017 17:40:23 +0000 (13:40 -0400)
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

src/bin/pg_dump/pg_dump.c
src/bin/psql/describe.c

index 8733426e8aca4f7bcd8071afc43c9538ef04861b..b807df58a85dd3a67efdcc81d127c42c0f914228 100644 (file)
@@ -13160,7 +13160,7 @@ dumpCollation(Archive *fout, CollInfo *collinfo)
                          collinfo->dobj.catId.oid);
    else
        appendPQExpBuffer(query, "SELECT "
-                         "'c'::char AS collprovider, "
+                         "'c' AS collprovider, "
                          "collcollate, "
                          "collctype, "
                          "NULL AS collversion "
@@ -16549,13 +16549,16 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
        /*
         * Before PostgreSQL 10, sequence metadata is in the sequence itself,
         * so switch to the sequence's schema instead of pg_catalog.
+        *
+        * Note: it might seem that 'bigint' potentially needs to be
+        * schema-qualified, but actually that's a keyword.
         */
 
        /* Make sure we are in proper schema */
        selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
 
        appendPQExpBuffer(query,
-                         "SELECT 'bigint'::name AS sequence_type, "
+                         "SELECT 'bigint' AS sequence_type, "
                          "start_value, increment_by, max_value, min_value, "
                          "cache_value, is_cycled FROM %s",
                          fmtId(tbinfo->dobj.name));
@@ -16566,7 +16569,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
        selectSourceSchema(fout, tbinfo->dobj.namespace->dobj.name);
 
        appendPQExpBuffer(query,
-                         "SELECT 'bigint'::name AS sequence_type, "
+                         "SELECT 'bigint' AS sequence_type, "
                          "0 AS start_value, increment_by, max_value, min_value, "
                          "cache_value, is_cycled FROM %s",
                          fmtId(tbinfo->dobj.name));
index 638275ca2f97c3d13dcdbdfce1ef8f75c677465d..986172616ee91cc88de6f3214ceefa02cbd706fb 100644 (file)
@@ -1596,7 +1596,7 @@ describeOneTableDetails(const char *schemaname,
        else
        {
            printfPQExpBuffer(&buf,
-                             "SELECT pg_catalog.format_type('bigint'::regtype, NULL) AS \"%s\",\n"
+                             "SELECT 'bigint' AS \"%s\",\n"
                              "       start_value AS \"%s\",\n"
                              "       min_value AS \"%s\",\n"
                              "       max_value AS \"%s\",\n"
@@ -2489,7 +2489,7 @@ describeOneTableDetails(const char *schemaname,
            {
                printfPQExpBuffer(&buf,
                                  "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
-                                 "'O'::char AS ev_enabled\n"
+                                 "'O' AS ev_enabled\n"
                                  "FROM pg_catalog.pg_rewrite r\n"
                                  "WHERE r.ev_class = '%s' ORDER BY 1;",
                                  oid);