Fix psql's \d command to show per-column generic options for foreign
authorShigeru Hanada <[email protected]>
Wed, 15 Jun 2011 08:12:54 +0000 (17:12 +0900)
committerShigeru Hanada <[email protected]>
Mon, 20 Jun 2011 04:32:04 +0000 (13:32 +0900)
tables.

doc/src/sgml/ref/psql-ref.sgml
src/bin/psql/describe.c
src/test/regress/expected/foreign_data.out

index 132a7b354b625826c2f5769cc3ab14bfecfa9d8f..74b26b24866e763d4b03de6053615a06aa58f59e 100644 (file)
@@ -891,6 +891,13 @@ testdb=&gt;
         below.)
         </para>
 
+       <para>
+        In addition to common information, <literal>\d</> shows
+        relation-kind-specific information for each column:
+        column values for sequences, indexed expression for indexes and
+        per-column generic options for foreign tables.
+       </para>
+
         <para>
         The command form <literal>\d+</literal> is identical, except that
         more information is displayed: any comments associated with the
index 7f9e1fe8440150476def4eff95e273b143c1ac17..381150c75ad7f3eaf75fa212ed9f8d0f1ed4a04f 100644 (file)
@@ -1302,6 +1302,10 @@ describeOneTableDetails(const char *schemaname,
        appendPQExpBuffer(&buf, ",\n  pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef");
    else
        appendPQExpBuffer(&buf, ",\n  NULL AS indexdef");
+   if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
+       appendPQExpBuffer(&buf, ",\n  a.attfdwoptions");
+   else
+       appendPQExpBuffer(&buf, ",\n  NULL AS attfdwoptions");
    if (verbose)
        appendPQExpBuffer(&buf, ",\n  a.attstorage, pg_catalog.col_description(a.attrelid, a.attnum)");
    appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a");
@@ -1383,6 +1387,9 @@ describeOneTableDetails(const char *schemaname,
    if (tableinfo.relkind == 'i')
        headers[cols++] = gettext_noop("Definition");
 
+   if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
+       headers[cols++] = gettext_noop("Options");
+
    if (verbose)
    {
        headers[cols++] = gettext_noop("Storage");
@@ -1465,10 +1472,14 @@ describeOneTableDetails(const char *schemaname,
        if (tableinfo.relkind == 'i')
            printTableAddCell(&cont, PQgetvalue(res, i, 6), false, false);
 
+       /* FDW options for foreign table column, only for 9.2 or later */
+       if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
+           printTableAddCell(&cont, PQgetvalue(res, i, 7), false, false);
+
        /* Storage and Description */
        if (verbose)
        {
-           int         firstvcol = 7;
+           int         firstvcol = 8;
            char       *storage = PQgetvalue(res, i, firstvcol);
 
            /* these strings are literal in our syntax, so not translated. */
index 64c87685b26dca075e47d34d89108d7e3315a8e6..60522fe978dfac7e0d69176e949b73d4aa6a6b24 100644 (file)
@@ -653,12 +653,12 @@ CREATE FOREIGN TABLE ft1 (
 COMMENT ON FOREIGN TABLE ft1 IS 'ft1';
 COMMENT ON COLUMN ft1.c1 IS 'ft1.c1';
 \d+ ft1
-              Foreign table "public.ft1"
- Column |  Type   | Modifiers | Storage  | Description 
---------+---------+-----------+----------+-------------
- c1     | integer | not null  | plain    | ft1.c1
- c2     | text    |           | extended | 
- c3     | date    |           | plain    | 
+                            Foreign table "public.ft1"
+ Column |  Type   | Modifiers |          Options          | Storage  | Description 
+--------+---------+-----------+---------------------------+----------+-------------
+ c1     | integer | not null  | {param1=val1}             | plain    | ft1.c1
+ c2     | text    |           | {param2=val2,param3=val3} | extended | 
+ c3     | date    |           |                           | plain    | 
 Server: sc
 Has OIDs: no
 
@@ -704,18 +704,18 @@ ALTER FOREIGN TABLE ft1 ALTER COLUMN c7 OPTIONS (ADD p1 'v1', ADD p2 'v2'),
                         ALTER COLUMN c8 OPTIONS (ADD p1 'v1', ADD p2 'v2');
 ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 OPTIONS (SET p2 'V2', DROP p1);
 \d+ ft1
-              Foreign table "public.ft1"
- Column |  Type   | Modifiers | Storage  | Description 
---------+---------+-----------+----------+-------------
- c1     | integer | not null  | plain    | 
- c2     | text    |           | extended | 
- c3     | date    |           | plain    | 
- c4     | integer |           | plain    | 
- c6     | integer | not null  | plain    | 
- c7     | integer |           | plain    | 
- c8     | text    |           | extended | 
- c9     | integer |           | plain    | 
- c10    | integer |           | plain    | 
+                            Foreign table "public.ft1"
+ Column |  Type   | Modifiers |          Options          | Storage  | Description 
+--------+---------+-----------+---------------------------+----------+-------------
+ c1     | integer | not null  | {param1=val1}             | plain    | 
+ c2     | text    |           | {param2=val2,param3=val3} | extended | 
+ c3     | date    |           |                           | plain    | 
+ c4     | integer |           |                           | plain    | 
+ c6     | integer | not null  |                           | plain    | 
+ c7     | integer |           | {p1=v1,p2=v2}             | plain    | 
+ c8     | text    |           | {p2=V2}                   | extended | 
+ c9     | integer |           |                           | plain    | 
+ c10    | integer |           | {p1=v1}                   | plain    | 
 Server: sc
 Has OIDs: no
 
@@ -747,17 +747,17 @@ ERROR:  relation "ft1" does not exist
 ALTER FOREIGN TABLE foreign_schema.ft1 RENAME c1 TO foreign_column_1;
 ALTER FOREIGN TABLE foreign_schema.ft1 RENAME TO foreign_table_1;
 \d foreign_schema.foreign_table_1
-Foreign table "foreign_schema.foreign_table_1"
-      Column      |  Type   | Modifiers 
-------------------+---------+-----------
- foreign_column_1 | integer | not null
- c2               | text    | 
- c3               | date    | 
- c4               | integer | 
- c6               | integer | not null
- c7               | integer | 
- c8               | text    | 
- c10              | integer | 
+           Foreign table "foreign_schema.foreign_table_1"
+      Column      |  Type   | Modifiers |          Options          
+------------------+---------+-----------+---------------------------
+ foreign_column_1 | integer | not null  | {param1=val1}
+ c2               | text    |           | {param2=val2,param3=val3}
+ c3               | date    |           | 
+ c4               | integer |           | 
+ c6               | integer | not null  | 
+ c7               | integer |           | {p1=v1,p2=v2}
+ c8               | text    |           | {p2=V2}
+ c10              | integer |           | {p1=v1}
 Server: sc
 
 -- Information schema