Fix psql to avoid variable width query with using NULL as placeholder.
authorShigeru Hanada <[email protected]>
Wed, 15 Jun 2011 03:02:20 +0000 (12:02 +0900)
committerShigeru Hanada <[email protected]>
Mon, 20 Jun 2011 04:32:02 +0000 (13:32 +0900)
src/bin/psql/describe.c

index b2c54b5f929c8c32ed2c8c015cb1981cf5116866..7f9e1fe8440150476def4eff95e273b143c1ac17 100644 (file)
@@ -1281,7 +1281,12 @@ describeOneTableDetails(const char *schemaname,
        res = NULL;
    }
 
-   /* Get column info */
+   /*
+    * Get column info
+    *
+    * You need to modify value of "firstvcol" which willbe defined below if
+    * you are adding column(s) preceding to verbose-only columns.
+    */
    printfPQExpBuffer(&buf, "SELECT a.attname,");
    appendPQExpBuffer(&buf, "\n  pg_catalog.format_type(a.atttypid, a.atttypmod),"
                      "\n  (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)"
@@ -1295,6 +1300,8 @@ describeOneTableDetails(const char *schemaname,
        appendPQExpBuffer(&buf, "\n  NULL AS attcollation");
    if (tableinfo.relkind == 'i')
        appendPQExpBuffer(&buf, ",\n  pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef");
+   else
+       appendPQExpBuffer(&buf, ",\n  NULL AS indexdef");
    if (verbose)
        appendPQExpBuffer(&buf, ",\n  a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)");
    appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
@@ -1461,7 +1468,7 @@ describeOneTableDetails(const char *schemaname,
        /* Storage and Description */
        if (verbose)
        {
-           int         firstvcol = (tableinfo.relkind == 'i' ? 7 : 6);
+           int         firstvcol = 7;
            char       *storage = PQgetvalue(res, i, firstvcol);
 
            /* these strings are literal in our syntax, so not translated. */