@@ -2870,7 +2870,9 @@ describeOneTableDetails(const char *schemaname,
2870
2870
/* print child tables (with additional info if partitions) */
2871
2871
if (pset .sversion >= 100000 )
2872
2872
printfPQExpBuffer (& buf ,
2873
- "SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid)"
2873
+ "SELECT c.oid::pg_catalog.regclass,"
2874
+ " pg_catalog.pg_get_expr(c.relpartbound, c.oid),"
2875
+ " c.relkind"
2874
2876
" FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i"
2875
2877
" WHERE c.oid=i.inhrelid AND i.inhparent = '%s'"
2876
2878
" ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;" , oid );
@@ -2893,7 +2895,18 @@ describeOneTableDetails(const char *schemaname,
2893
2895
else
2894
2896
tuples = PQntuples (result );
2895
2897
2896
- if (!verbose )
2898
+ /*
2899
+ * For a partitioned table with no partitions, always print the number
2900
+ * of partitions as zero, even when verbose output is expected.
2901
+ * Otherwise, we will not print "Partitions" section for a partitioned
2902
+ * table without any partitions.
2903
+ */
2904
+ if (tableinfo .relkind == RELKIND_PARTITIONED_TABLE && tuples == 0 )
2905
+ {
2906
+ printfPQExpBuffer (& buf , _ ("Number of partitions: %d" ), tuples );
2907
+ printTableAddFooter (& cont , buf .data );
2908
+ }
2909
+ else if (!verbose )
2897
2910
{
2898
2911
/* print the number of child tables, if any */
2899
2912
if (tuples > 0 )
@@ -2925,12 +2938,21 @@ describeOneTableDetails(const char *schemaname,
2925
2938
}
2926
2939
else
2927
2940
{
2941
+ char * partitioned_note ;
2942
+
2943
+ if (* PQgetvalue (result , i , 2 ) == RELKIND_PARTITIONED_TABLE )
2944
+ partitioned_note = ", PARTITIONED" ;
2945
+ else
2946
+ partitioned_note = "" ;
2947
+
2928
2948
if (i == 0 )
2929
- printfPQExpBuffer (& buf , "%s: %s %s" ,
2930
- ct , PQgetvalue (result , i , 0 ), PQgetvalue (result , i , 1 ));
2949
+ printfPQExpBuffer (& buf , "%s: %s %s%s" ,
2950
+ ct , PQgetvalue (result , i , 0 ), PQgetvalue (result , i , 1 ),
2951
+ partitioned_note );
2931
2952
else
2932
- printfPQExpBuffer (& buf , "%*s %s %s" ,
2933
- ctw , "" , PQgetvalue (result , i , 0 ), PQgetvalue (result , i , 1 ));
2953
+ printfPQExpBuffer (& buf , "%*s %s %s%s" ,
2954
+ ctw , "" , PQgetvalue (result , i , 0 ), PQgetvalue (result , i , 1 ),
2955
+ partitioned_note );
2934
2956
}
2935
2957
if (i < tuples - 1 )
2936
2958
appendPQExpBufferChar (& buf , ',' );
0 commit comments