show_per_table_options.patch

text/plain

Filename: show_per_table_options.patch
Type: text/plain
Part: 0
Message: Re: psql document fix about showing FDW options
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index db97df1..e8b4f73 100644
*** a/doc/src/sgml/ref/psql-ref.sgml
--- b/doc/src/sgml/ref/psql-ref.sgml
*************** testdb=>
*** 892,906 ****
          <para>
          For some types of relation, <literal>\d</> shows additional information
          for each column: column values for sequences, indexed expression for
!         indexes and per-column foreign data wrapper 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
          columns of the table are shown, as is the presence of OIDs in the
!         table, the view definition if the relation is a view, and the generic
!         options if the relation is a foreign table.
          </para>
  
          <para>
--- 892,905 ----
          <para>
          For some types of relation, <literal>\d</> shows additional information
          for each column: column values for sequences, indexed expression for
!         indexes and foreign data wrapper 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
          columns of the table are shown, as is the presence of OIDs in the
!         table, the view definition if the relation is a view.
          </para>
  
          <para>
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index f08f917..0f54964 100644
*** a/src/bin/psql/describe.c
--- b/src/bin/psql/describe.c
*************** describeOneTableDetails(const char *sche
*** 2064,2072 ****
  		/* print foreign server name */
  		if (tableinfo.relkind == 'f')
  		{
  			/* Footer information about foreign table */
  			printfPQExpBuffer(&buf,
! 							  "SELECT s.srvname\n"
  							  "FROM pg_catalog.pg_foreign_table f,\n"
  							  "     pg_catalog.pg_foreign_server s\n"
  							  "WHERE f.ftrelid = %s AND s.oid = f.ftserver;",
--- 2064,2075 ----
  		/* print foreign server name */
  		if (tableinfo.relkind == 'f')
  		{
+ 			char *ftoptions;
+ 
  			/* Footer information about foreign table */
  			printfPQExpBuffer(&buf,
! 							  "SELECT s.srvname,\n"
! 							  "       f.ftoptions\n"
  							  "FROM pg_catalog.pg_foreign_table f,\n"
  							  "     pg_catalog.pg_foreign_server s\n"
  							  "WHERE f.ftrelid = %s AND s.oid = f.ftserver;",
*************** describeOneTableDetails(const char *sche
*** 2080,2088 ****
--- 2083,2100 ----
  				goto error_return;
  			}
  
+ 			/* Print server name */
  			printfPQExpBuffer(&buf, "Server: %s",
  							  PQgetvalue(result, 0, 0));
  			printTableAddFooter(&cont, buf.data);
+ 
+ 			/* Print per-table FDW options, if any */
+ 			ftoptions = PQgetvalue(result, 0, 1);
+ 			if (ftoptions && ftoptions[0] != '\0')
+ 			{
+ 				printfPQExpBuffer(&buf, "Options: %s", ftoptions);
+ 				printTableAddFooter(&cont, buf.data);
+ 			}
  			PQclear(result);
  		}
  
diff --git a/src/test/regress/expected/foreign_data.out b/src/test/regress/expected/foreign_data.out
index ef13f27..5c48d83 100644
*** a/src/test/regress/expected/foreign_data.out
--- b/src/test/regress/expected/foreign_data.out
*************** COMMENT ON COLUMN ft1.c1 IS 'ft1.c1';
*** 660,665 ****
--- 660,666 ----
   c2     | text    |           | {param2=val2,param3=val3} | extended | 
   c3     | date    |           |                           | plain    | 
  Server: sc
+ Options: {"delimiter=,","quote=\""}
  Has OIDs: no
  
  \det+
*************** ALTER FOREIGN TABLE ft1 ALTER COLUMN c8 
*** 717,722 ****
--- 718,724 ----
   c9     | integer |           |                           | plain    | 
   c10    | integer |           | {p1=v1}                   | plain    | 
  Server: sc
+ Options: {"delimiter=,","quote=\""}
  Has OIDs: no
  
  -- can't change the column type if it's used elsewhere
*************** ALTER FOREIGN TABLE foreign_schema.ft1 R
*** 759,764 ****
--- 761,767 ----
   c8               | text    |           | {p2=V2}
   c10              | integer |           | {p1=v1}
  Server: sc
+ Options: {quote=~,escape=@}
  
  -- Information schema
  SELECT * FROM information_schema.foreign_data_wrappers ORDER BY 1, 2;