Bizarre choice of case for RELKIND_PARTITIONED_TABLE

Started by Tom Lanealmost 9 years ago12 messages
#1Tom Lane
tgl@sss.pgh.pa.us

Is there a good reason why RELKIND_PARTITIONED_TABLE is 'P' not 'p'?
It looks rather out of place considering that seven of the eight
pre-existing relkind codes are lower case. (And no, I don't especially
approve of RELKIND_SEQUENCE being 'S' either, but it's far too late to
change that.) Also, in typical low-res monospaced fonts, there's nearly
no difference except vertical alignment between P and p, meaning that in
something like

regression=# select distinct relkind from pg_class;
relkind
---------
r
t
P
v
m
i
S
c
(8 rows)

you have to look rather closely even to notice that what you're seeing
isn't in the case you might expect.

I think we should change this while we still can.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#1)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

On Tue, Mar 7, 2017 at 12:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Is there a good reason why RELKIND_PARTITIONED_TABLE is 'P' not 'p'?
It looks rather out of place considering that seven of the eight
pre-existing relkind codes are lower case. (And no, I don't especially
approve of RELKIND_SEQUENCE being 'S' either, but it's far too late to
change that.) Also, in typical low-res monospaced fonts, there's nearly
no difference except vertical alignment between P and p, meaning that in
something like

regression=# select distinct relkind from pg_class;
relkind
---------
r
t
P
v
m
i
S
c
(8 rows)

you have to look rather closely even to notice that what you're seeing
isn't in the case you might expect.

I think we should change this while we still can.

I can't muster a lot of outrage about this one way or another. One
possible advantage of 'P' is that there are fewer places where 'P' is
mentioned in the source code than 'p'.

[rhaas pgsql]$ git grep "'p'" | wc -l
293
[rhaas pgsql]$ git grep "'P'" | wc -l
104

...so it's a little easier to pick out the cases that are talking
about partitioned tables than it would be with a lower case letter.
However, as I say, I don't care very much.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#2)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

Robert Haas <robertmhaas@gmail.com> writes:

On Tue, Mar 7, 2017 at 12:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Is there a good reason why RELKIND_PARTITIONED_TABLE is 'P' not 'p'?

I can't muster a lot of outrage about this one way or another. One
possible advantage of 'P' is that there are fewer places where 'P' is
mentioned in the source code than 'p'.

Hm, one would hope that the vast majority of code references are neither
of those, but rather "RELKIND_PARTITIONED_TABLE". information_schema.sql
and system_views.sql will need to be gone over carefully, certainly, but
we shouldn't be hard-coding this anywhere that there's a reasonable
alternative.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Tom Lane (#1)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

On 3/7/17 12:55, Tom Lane wrote:

Is there a good reason why RELKIND_PARTITIONED_TABLE is 'P' not 'p'?

I was confused about this too. If there is no argument against it, I
would favor changing it.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#3)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

On Tue, Mar 7, 2017 at 6:03 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <robertmhaas@gmail.com> writes:

On Tue, Mar 7, 2017 at 12:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Is there a good reason why RELKIND_PARTITIONED_TABLE is 'P' not 'p'?

I can't muster a lot of outrage about this one way or another. One
possible advantage of 'P' is that there are fewer places where 'P' is
mentioned in the source code than 'p'.

Hm, one would hope that the vast majority of code references are neither
of those, but rather "RELKIND_PARTITIONED_TABLE". information_schema.sql
and system_views.sql will need to be gone over carefully, certainly, but
we shouldn't be hard-coding this anywhere that there's a reasonable
alternative.

For reasons which must've seemed good to whoever instituted the
policy, pg_dump refers to relkinds using the bare letters rather than
the constants.

(And protocol message types don't even have defined constants. Uggh.)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#5)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

Robert Haas <robertmhaas@gmail.com> writes:

On Tue, Mar 7, 2017 at 6:03 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Hm, one would hope that the vast majority of code references are neither
of those, but rather "RELKIND_PARTITIONED_TABLE".

For reasons which must've seemed good to whoever instituted the
policy, pg_dump refers to relkinds using the bare letters rather than
the constants.

Even in pg_dump, it appears to me that the large majority of relkind
references use the symbolic names. Quite a few of the violations of
that policy look to be new ... and now that I see them, their days are
numbered.

(And protocol message types don't even have defined constants. Uggh.)

Yeah, that's a different issue, which boils down to the fact that in order
to do anything useful we'd need to clutter client-visible namespace with
the symbols. I wouldn't be averse to doing something about it as long as
it's not done in postgres_ext.h, but if not there where?

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Amit Langote
Langote_Amit_f8@lab.ntt.co.jp
In reply to: Tom Lane (#1)
1 attachment(s)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

On 2017/03/08 2:55, Tom Lane wrote:

Is there a good reason why RELKIND_PARTITIONED_TABLE is 'P' not 'p'?
It looks rather out of place considering that seven of the eight
pre-existing relkind codes are lower case. (And no, I don't especially
approve of RELKIND_SEQUENCE being 'S' either, but it's far too late to
change that.) Also, in typical low-res monospaced fonts, there's nearly
no difference except vertical alignment between P and p, meaning that in
something like

regression=# select distinct relkind from pg_class;
relkind
---------
r
t
P
v
m
i
S
c
(8 rows)

you have to look rather closely even to notice that what you're seeing
isn't in the case you might expect.

I think we should change this while we still can.

I remember that one of the earliest versions of the patch I submitted had
two new relkinds: 'P' for partitioned tables and 'p' for leaf partitions.
The latter was dropped subsequently and I never thought of using 'p'
instead of 'P' for partitioned tables.

Attached patch that implements this change.

Thanks,
Amit

Attachments:

0001-Change-RELKIND_PARTITIONED_TABLE-to-p.patchtext/x-diff; name=0001-Change-RELKIND_PARTITIONED_TABLE-to-p.patchDownload
From b356a5e61aedc9fcf4edd99a095b06c5c8e57a86 Mon Sep 17 00:00:00 2001
From: amit <amitlangote09@gmail.com>
Date: Wed, 8 Mar 2017 12:07:56 +0900
Subject: [PATCH] Change RELKIND_PARTITIONED_TABLE to 'p'

---
 src/backend/catalog/information_schema.sql | 40 +++++++++++++++---------------
 src/backend/catalog/system_views.sql       |  4 +--
 src/bin/pg_dump/pg_dump.c                  |  2 +-
 src/bin/psql/describe.c                    | 38 ++++++++++++++--------------
 src/bin/psql/tab-complete.c                |  8 +++---
 src/include/catalog/pg_class.h             |  2 +-
 src/test/regress/expected/create_table.out |  2 +-
 src/test/regress/expected/rules.out        |  4 +--
 src/test/regress/expected/sanity_check.out |  2 +-
 src/test/regress/sql/sanity_check.sql      |  2 +-
 10 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/src/backend/catalog/information_schema.sql b/src/backend/catalog/information_schema.sql
index 51795cd6de..0011e06494 100644
--- a/src/backend/catalog/information_schema.sql
+++ b/src/backend/catalog/information_schema.sql
@@ -453,7 +453,7 @@ CREATE VIEW check_constraints AS
       AND a.attnum > 0
       AND NOT a.attisdropped
       AND a.attnotnull
-      AND r.relkind IN ('r', 'P')
+      AND r.relkind IN ('r', 'p')
       AND pg_has_role(r.relowner, 'USAGE');
 
 GRANT SELECT ON check_constraints TO PUBLIC;
@@ -525,7 +525,7 @@ CREATE VIEW column_domain_usage AS
           AND a.attrelid = c.oid
           AND a.atttypid = t.oid
           AND t.typtype = 'd'
-          AND c.relkind IN ('r', 'v', 'f', 'P')
+          AND c.relkind IN ('r', 'v', 'f', 'p')
           AND a.attnum > 0
           AND NOT a.attisdropped
           AND pg_has_role(t.typowner, 'USAGE');
@@ -564,7 +564,7 @@ CREATE VIEW column_privileges AS
                   pr_c.relowner
            FROM (SELECT oid, relname, relnamespace, relowner, (aclexplode(coalesce(relacl, acldefault('r', relowner)))).*
                  FROM pg_class
-                 WHERE relkind IN ('r', 'v', 'f', 'P')
+                 WHERE relkind IN ('r', 'v', 'f', 'p')
                 ) pr_c (oid, relname, relnamespace, relowner, grantor, grantee, prtype, grantable),
                 pg_attribute a
            WHERE a.attrelid = pr_c.oid
@@ -586,7 +586,7 @@ CREATE VIEW column_privileges AS
                 ) pr_a (attrelid, attname, grantor, grantee, prtype, grantable),
                 pg_class c
            WHERE pr_a.attrelid = c.oid
-                 AND relkind IN ('r', 'v', 'f', 'P')
+                 AND relkind IN ('r', 'v', 'f', 'p')
          ) x,
          pg_namespace nc,
          pg_authid u_grantor,
@@ -629,7 +629,7 @@ CREATE VIEW column_udt_usage AS
     WHERE a.attrelid = c.oid
           AND a.atttypid = t.oid
           AND nc.oid = c.relnamespace
-          AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f', 'P')
+          AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f', 'p')
           AND pg_has_role(coalesce(bt.typowner, t.typowner), 'USAGE');
 
 GRANT SELECT ON column_udt_usage TO PUBLIC;
@@ -738,7 +738,7 @@ CREATE VIEW columns AS
            CAST('NEVER' AS character_data) AS is_generated,
            CAST(null AS character_data) AS generation_expression,
 
-           CAST(CASE WHEN c.relkind IN ('r', 'P') OR
+           CAST(CASE WHEN c.relkind IN ('r', 'p') OR
                           (c.relkind IN ('v', 'f') AND
                            pg_column_is_updatable(c.oid, a.attnum, false))
                 THEN 'YES' ELSE 'NO' END AS yes_or_no) AS is_updatable
@@ -753,7 +753,7 @@ CREATE VIEW columns AS
 
     WHERE (NOT pg_is_other_temp_schema(nc.oid))
 
-          AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f', 'P')
+          AND a.attnum > 0 AND NOT a.attisdropped AND c.relkind in ('r', 'v', 'f', 'p')
 
           AND (pg_has_role(c.relowner, 'USAGE')
                OR has_column_privilege(c.oid, a.attnum,
@@ -789,7 +789,7 @@ CREATE VIEW constraint_column_usage AS
             AND d.objid = c.oid
             AND c.connamespace = nc.oid
             AND c.contype = 'c'
-            AND r.relkind IN ('r', 'P')
+            AND r.relkind IN ('r', 'p')
             AND NOT a.attisdropped
 
         UNION ALL
@@ -805,7 +805,7 @@ CREATE VIEW constraint_column_usage AS
             AND a.attnum = ANY (CASE c.contype WHEN 'f' THEN c.confkey ELSE c.conkey END)
             AND NOT a.attisdropped
             AND c.contype IN ('p', 'u', 'f')
-            AND r.relkind IN ('r', 'P')
+            AND r.relkind IN ('r', 'p')
 
       ) AS x (tblschema, tblname, tblowner, colname, cstrschema, cstrname)
 
@@ -841,7 +841,7 @@ CREATE VIEW constraint_table_usage AS
     WHERE c.connamespace = nc.oid AND r.relnamespace = nr.oid
           AND ( (c.contype = 'f' AND c.confrelid = r.oid)
              OR (c.contype IN ('p', 'u') AND c.conrelid = r.oid) )
-          AND r.relkind IN ('r', 'P')
+          AND r.relkind IN ('r', 'p')
           AND pg_has_role(r.relowner, 'USAGE');
 
 GRANT SELECT ON constraint_table_usage TO PUBLIC;
@@ -1058,7 +1058,7 @@ CREATE VIEW key_column_usage AS
                 AND r.oid = c.conrelid
                 AND nc.oid = c.connamespace
                 AND c.contype IN ('p', 'u', 'f')
-                AND r.relkind IN ('r', 'P')
+                AND r.relkind IN ('r', 'p')
                 AND (NOT pg_is_other_temp_schema(nr.oid)) ) AS ss
     WHERE ss.roid = a.attrelid
           AND a.attnum = (ss.x).x
@@ -1774,7 +1774,7 @@ CREATE VIEW table_constraints AS
     WHERE nc.oid = c.connamespace AND nr.oid = r.relnamespace
           AND c.conrelid = r.oid
           AND c.contype NOT IN ('t', 'x')  -- ignore nonstandard constraints
-          AND r.relkind IN ('r', 'P')
+          AND r.relkind IN ('r', 'p')
           AND (NOT pg_is_other_temp_schema(nr.oid))
           AND (pg_has_role(r.relowner, 'USAGE')
                -- SELECT privilege omitted, per SQL standard
@@ -1804,7 +1804,7 @@ CREATE VIEW table_constraints AS
           AND a.attnotnull
           AND a.attnum > 0
           AND NOT a.attisdropped
-          AND r.relkind IN ('r', 'P')
+          AND r.relkind IN ('r', 'p')
           AND (NOT pg_is_other_temp_schema(nr.oid))
           AND (pg_has_role(r.relowner, 'USAGE')
                -- SELECT privilege omitted, per SQL standard
@@ -1854,7 +1854,7 @@ CREATE VIEW table_privileges AS
          ) AS grantee (oid, rolname)
 
     WHERE c.relnamespace = nc.oid
-          AND c.relkind IN ('r', 'v', 'P')
+          AND c.relkind IN ('r', 'v', 'p')
           AND c.grantee = grantee.oid
           AND c.grantor = u_grantor.oid
           AND c.prtype IN ('INSERT', 'SELECT', 'UPDATE', 'DELETE', 'TRUNCATE', 'REFERENCES', 'TRIGGER')
@@ -1898,7 +1898,7 @@ CREATE VIEW tables AS
 
            CAST(
              CASE WHEN nc.oid = pg_my_temp_schema() THEN 'LOCAL TEMPORARY'
-                  WHEN c.relkind IN ('r', 'P') THEN 'BASE TABLE'
+                  WHEN c.relkind IN ('r', 'p') THEN 'BASE TABLE'
                   WHEN c.relkind = 'v' THEN 'VIEW'
                   WHEN c.relkind = 'f' THEN 'FOREIGN TABLE'
                   ELSE null END
@@ -1911,7 +1911,7 @@ CREATE VIEW tables AS
            CAST(nt.nspname AS sql_identifier) AS user_defined_type_schema,
            CAST(t.typname AS sql_identifier) AS user_defined_type_name,
 
-           CAST(CASE WHEN c.relkind IN ('r', 'P') OR
+           CAST(CASE WHEN c.relkind IN ('r', 'p') OR
                           (c.relkind IN ('v', 'f') AND
                            -- 1 << CMD_INSERT
                            pg_relation_is_updatable(c.oid, false) & 8 = 8)
@@ -1923,7 +1923,7 @@ CREATE VIEW tables AS
     FROM pg_namespace nc JOIN pg_class c ON (nc.oid = c.relnamespace)
            LEFT JOIN (pg_type t JOIN pg_namespace nt ON (t.typnamespace = nt.oid)) ON (c.reloftype = t.oid)
 
-    WHERE c.relkind IN ('r', 'v', 'f', 'P')
+    WHERE c.relkind IN ('r', 'v', 'f', 'p')
           AND (NOT pg_is_other_temp_schema(nc.oid))
           AND (pg_has_role(c.relowner, 'USAGE')
                OR has_table_privilege(c.oid, 'SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER')
@@ -2442,7 +2442,7 @@ CREATE VIEW view_column_usage AS
           AND dt.refclassid = 'pg_catalog.pg_class'::regclass
           AND dt.refobjid = t.oid
           AND t.relnamespace = nt.oid
-          AND t.relkind IN ('r', 'v', 'f', 'P')
+          AND t.relkind IN ('r', 'v', 'f', 'p')
           AND t.oid = a.attrelid
           AND dt.refobjsubid = a.attnum
           AND pg_has_role(t.relowner, 'USAGE');
@@ -2520,7 +2520,7 @@ CREATE VIEW view_table_usage AS
           AND dt.refclassid = 'pg_catalog.pg_class'::regclass
           AND dt.refobjid = t.oid
           AND t.relnamespace = nt.oid
-          AND t.relkind IN ('r', 'v', 'f', 'P')
+          AND t.relkind IN ('r', 'v', 'f', 'p')
           AND pg_has_role(t.relowner, 'USAGE');
 
 GRANT SELECT ON view_table_usage TO PUBLIC;
@@ -2673,7 +2673,7 @@ CREATE VIEW element_types AS
                   a.attnum, a.atttypid, a.attcollation
            FROM pg_class c, pg_attribute a
            WHERE c.oid = a.attrelid
-                 AND c.relkind IN ('r', 'v', 'f', 'c', 'P')
+                 AND c.relkind IN ('r', 'v', 'f', 'c', 'p')
                  AND attnum > 0 AND NOT attisdropped
 
            UNION ALL
diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql
index ba980de86b..0bce20914e 100644
--- a/src/backend/catalog/system_views.sql
+++ b/src/backend/catalog/system_views.sql
@@ -136,7 +136,7 @@ CREATE VIEW pg_tables AS
         C.relrowsecurity AS rowsecurity
     FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
          LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace)
-    WHERE C.relkind IN ('r', 'P');
+    WHERE C.relkind IN ('r', 'p');
 
 CREATE VIEW pg_matviews AS
     SELECT
@@ -294,7 +294,7 @@ CREATE VIEW pg_prepared_statements AS
 CREATE VIEW pg_seclabels AS
 SELECT
 	l.objoid, l.classoid, l.objsubid,
-	CASE WHEN rel.relkind IN ('r', 'P') THEN 'table'::text
+	CASE WHEN rel.relkind IN ('r', 'p') THEN 'table'::text
 		 WHEN rel.relkind = 'v' THEN 'view'::text
 		 WHEN rel.relkind = 'm' THEN 'materialized view'::text
 		 WHEN rel.relkind = 'S' THEN 'sequence'::text
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index c7876fedd2..3da4097ecb 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -6174,7 +6174,7 @@ getInherits(Archive *fout, int *numInherits)
 	appendPQExpBufferStr(query,
 						 "SELECT inhrelid, inhparent "
 						 "FROM pg_inherits "
-						 "WHERE inhparent NOT IN (SELECT oid FROM pg_class WHERE relkind = 'P')");
+						 "WHERE inhparent NOT IN (SELECT oid FROM pg_class WHERE relkind = 'p')");
 
 	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index e2e4cbcc08..43f85782b6 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -865,7 +865,7 @@ permissionsList(const char *pattern)
 					  " WHEN 'm' THEN '%s'"
 					  " WHEN 'S' THEN '%s'"
 					  " WHEN 'f' THEN '%s'"
-					  " WHEN 'P' THEN '%s'"
+					  " WHEN 'p' THEN '%s'"
 					  " END as \"%s\",\n"
 					  "  ",
 					  gettext_noop("Schema"),
@@ -956,7 +956,7 @@ permissionsList(const char *pattern)
 
 	appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
 	   "     LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
-						 "WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f', 'P')\n");
+						 "WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f', 'p')\n");
 
 	/*
 	 * Unless a schema pattern is specified, we suppress system and temp
@@ -1603,7 +1603,7 @@ describeOneTableDetails(const char *schemaname,
 		 */
 		if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
 			tableinfo.relkind == 'm' || tableinfo.relkind == 'f' ||
-			tableinfo.relkind == 'c' || tableinfo.relkind == 'P')
+			tableinfo.relkind == 'c' || tableinfo.relkind == 'p')
 			appendPQExpBufferStr(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)");
 	}
 
@@ -1668,7 +1668,7 @@ describeOneTableDetails(const char *schemaname,
 			printfPQExpBuffer(&title, _("Foreign table \"%s.%s\""),
 							  schemaname, relationname);
 			break;
-		case 'P':
+		case 'p':
 			if (tableinfo.relpersistence == 'u')
 				printfPQExpBuffer(&title, _("Unlogged table \"%s.%s\""),
 								  schemaname, relationname);
@@ -1690,7 +1690,7 @@ describeOneTableDetails(const char *schemaname,
 
 	if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
 		tableinfo.relkind == 'm' || tableinfo.relkind == 'f' ||
-		tableinfo.relkind == 'c' || tableinfo.relkind == 'P')
+		tableinfo.relkind == 'c' || tableinfo.relkind == 'p')
 	{
 		headers[cols++] = gettext_noop("Collation");
 		headers[cols++] = gettext_noop("Nullable");
@@ -1711,12 +1711,12 @@ describeOneTableDetails(const char *schemaname,
 	{
 		headers[cols++] = gettext_noop("Storage");
 		if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
-			tableinfo.relkind == 'f' || tableinfo.relkind == 'P')
+			tableinfo.relkind == 'f' || tableinfo.relkind == 'p')
 			headers[cols++] = gettext_noop("Stats target");
 		/* Column comments, if the relkind supports this feature. */
 		if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
 			tableinfo.relkind == 'm' || tableinfo.relkind == 'c' ||
-			tableinfo.relkind == 'f' || tableinfo.relkind == 'P')
+			tableinfo.relkind == 'f' || tableinfo.relkind == 'p')
 			headers[cols++] = gettext_noop("Description");
 	}
 
@@ -1792,7 +1792,7 @@ describeOneTableDetails(const char *schemaname,
 
 			/* Statistics target, if the relkind supports this feature */
 			if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
-				tableinfo.relkind == 'f' || tableinfo.relkind == 'P')
+				tableinfo.relkind == 'f' || tableinfo.relkind == 'p')
 			{
 				printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 1),
 								  false, false);
@@ -1801,7 +1801,7 @@ describeOneTableDetails(const char *schemaname,
 			/* Column comments, if the relkind supports this feature. */
 			if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
 				tableinfo.relkind == 'm' || tableinfo.relkind == 'c' ||
-				tableinfo.relkind == 'f' || tableinfo.relkind == 'P')
+				tableinfo.relkind == 'f' || tableinfo.relkind == 'p')
 				printTableAddCell(&cont, PQgetvalue(res, i, firstvcol + 2),
 								  false, false);
 		}
@@ -1836,7 +1836,7 @@ describeOneTableDetails(const char *schemaname,
 		}
 	}
 
-	if (tableinfo.relkind == 'P')
+	if (tableinfo.relkind == 'p')
 	{
 		/* Get the partition key information  */
 		PGresult   *result;
@@ -1993,7 +1993,7 @@ describeOneTableDetails(const char *schemaname,
 		PQclear(result);
 	}
 	else if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
-			 tableinfo.relkind == 'f' || tableinfo.relkind == 'P')
+			 tableinfo.relkind == 'f' || tableinfo.relkind == 'p')
 	{
 		/* Footer information about a table */
 		PGresult   *result = NULL;
@@ -2602,7 +2602,7 @@ describeOneTableDetails(const char *schemaname,
 	 * Finish printing the footer information about a table.
 	 */
 	if (tableinfo.relkind == 'r' || tableinfo.relkind == 'm' ||
-		tableinfo.relkind == 'f' || tableinfo.relkind == 'P')
+		tableinfo.relkind == 'f' || tableinfo.relkind == 'p')
 	{
 		PGresult   *result;
 		int			tuples;
@@ -2652,7 +2652,7 @@ describeOneTableDetails(const char *schemaname,
 				"SELECT c.oid::pg_catalog.regclass"
 				" FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i"
 				" WHERE c.oid=i.inhparent AND i.inhrelid = '%s'"
-				" AND c.relkind != 'P' ORDER BY inhseqno;", oid);
+				" AND c.relkind != 'p' ORDER BY inhseqno;", oid);
 
 		result = PSQLexec(buf.data);
 		if (!result)
@@ -2712,7 +2712,7 @@ describeOneTableDetails(const char *schemaname,
 			/* print the number of child tables, if any */
 			if (tuples > 0)
 			{
-				if (tableinfo.relkind != 'P')
+				if (tableinfo.relkind != 'p')
 					printfPQExpBuffer(&buf, _("Number of child tables: %d (Use \\d+ to list them.)"), tuples);
 				else
 					printfPQExpBuffer(&buf, _("Number of partitions: %d (Use \\d+ to list them.)"), tuples);
@@ -2722,12 +2722,12 @@ describeOneTableDetails(const char *schemaname,
 		else
 		{
 			/* display the list of child tables */
-			const char *ct = tableinfo.relkind != 'P' ? _("Child tables") : _("Partitions");
+			const char *ct = tableinfo.relkind != 'p' ? _("Child tables") : _("Partitions");
 			int			ctw = pg_wcswidth(ct, strlen(ct), pset.encoding);
 
 			for (i = 0; i < tuples; i++)
 			{
-				if (tableinfo.relkind != 'P')
+				if (tableinfo.relkind != 'p')
 				{
 					if (i == 0)
 						printfPQExpBuffer(&buf, "%s: %s",
@@ -2839,7 +2839,7 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
 					  Oid tablespace, const bool newline)
 {
 	/* relkinds for which we support tablespaces */
-	if (relkind == 'r' || relkind == 'm' || relkind == 'i' || relkind == 'P')
+	if (relkind == 'r' || relkind == 'm' || relkind == 'i' || relkind == 'p')
 	{
 		/*
 		 * We ignore the database default tablespace so that users not using
@@ -3173,7 +3173,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
 					  " WHEN 'S' THEN '%s'"
 					  " WHEN 's' THEN '%s'"
 					  " WHEN 'f' THEN '%s'"
-					  " WHEN 'P' THEN '%s'"
+					  " WHEN 'p' THEN '%s'"
 					  " END as \"%s\",\n"
 					  "  pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
 					  gettext_noop("Schema"),
@@ -3224,7 +3224,7 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
 
 	appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
 	if (showTables)
-		appendPQExpBufferStr(&buf, "'r', 'P',");
+		appendPQExpBufferStr(&buf, "'r', 'p',");
 	if (showViews)
 		appendPQExpBufferStr(&buf, "'v',");
 	if (showMatViews)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 121a492e6d..6360212883 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -452,7 +452,7 @@ static const SchemaQuery Query_for_list_of_tables = {
 	/* catname */
 	"pg_catalog.pg_class c",
 	/* selcondition */
-	"c.relkind IN ('r', 'P')",
+	"c.relkind IN ('r', 'p')",
 	/* viscondition */
 	"pg_catalog.pg_table_is_visible(c.oid)",
 	/* namespace */
@@ -467,7 +467,7 @@ static const SchemaQuery Query_for_list_of_partitioned_tables = {
 	/* catname */
 	"pg_catalog.pg_class c",
 	/* selcondition */
-	"c.relkind IN ('P')",
+	"c.relkind IN ('p')",
 	/* viscondition */
 	"pg_catalog.pg_table_is_visible(c.oid)",
 	/* namespace */
@@ -498,7 +498,7 @@ static const SchemaQuery Query_for_list_of_updatables = {
 	/* catname */
 	"pg_catalog.pg_class c",
 	/* selcondition */
-	"c.relkind IN ('r', 'f', 'v', 'P')",
+	"c.relkind IN ('r', 'f', 'v', 'p')",
 	/* viscondition */
 	"pg_catalog.pg_table_is_visible(c.oid)",
 	/* namespace */
@@ -528,7 +528,7 @@ static const SchemaQuery Query_for_list_of_tsvmf = {
 	/* catname */
 	"pg_catalog.pg_class c",
 	/* selcondition */
-	"c.relkind IN ('r', 'S', 'v', 'm', 'f', 'P')",
+	"c.relkind IN ('r', 'S', 'v', 'm', 'f', 'p')",
 	/* viscondition */
 	"pg_catalog.pg_table_is_visible(c.oid)",
 	/* namespace */
diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h
index 3f96611f74..2d420edf3f 100644
--- a/src/include/catalog/pg_class.h
+++ b/src/include/catalog/pg_class.h
@@ -165,7 +165,7 @@ DESCR("");
 #define		  RELKIND_COMPOSITE_TYPE  'c'		/* composite type */
 #define		  RELKIND_FOREIGN_TABLE   'f'		/* foreign table */
 #define		  RELKIND_MATVIEW		  'm'		/* materialized view */
-#define		  RELKIND_PARTITIONED_TABLE 'P'		/* partitioned table */
+#define		  RELKIND_PARTITIONED_TABLE 'p'		/* partitioned table */
 
 #define		  RELPERSISTENCE_PERMANENT	'p'		/* regular table */
 #define		  RELPERSISTENCE_UNLOGGED	'u'		/* unlogged permanent table */
diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out
index c07a474b3d..6f8645ddbd 100644
--- a/src/test/regress/expected/create_table.out
+++ b/src/test/regress/expected/create_table.out
@@ -404,7 +404,7 @@ CREATE TABLE partitioned (
 SELECT relkind FROM pg_class WHERE relname = 'partitioned';
  relkind 
 ---------
- P
+ p
 (1 row)
 
 -- check that range partition key columns are marked NOT NULL
diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out
index c661f1d962..bd13ae6010 100644
--- a/src/test/regress/expected/rules.out
+++ b/src/test/regress/expected/rules.out
@@ -1481,7 +1481,7 @@ pg_seclabels| SELECT l.objoid,
     l.classoid,
     l.objsubid,
         CASE
-            WHEN (rel.relkind = ANY (ARRAY['r'::"char", 'P'::"char"])) THEN 'table'::text
+            WHEN (rel.relkind = ANY (ARRAY['r'::"char", 'p'::"char"])) THEN 'table'::text
             WHEN (rel.relkind = 'v'::"char") THEN 'view'::text
             WHEN (rel.relkind = 'm'::"char") THEN 'materialized view'::text
             WHEN (rel.relkind = 'S'::"char") THEN 'sequence'::text
@@ -2171,7 +2171,7 @@ pg_tables| SELECT n.nspname AS schemaname,
    FROM ((pg_class c
      LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))
      LEFT JOIN pg_tablespace t ON ((t.oid = c.reltablespace)))
-  WHERE (c.relkind = ANY (ARRAY['r'::"char", 'P'::"char"]));
+  WHERE (c.relkind = ANY (ARRAY['r'::"char", 'p'::"char"]));
 pg_timezone_abbrevs| SELECT pg_timezone_abbrevs.abbrev,
     pg_timezone_abbrevs.utc_offset,
     pg_timezone_abbrevs.is_dst
diff --git a/src/test/regress/expected/sanity_check.out b/src/test/regress/expected/sanity_check.out
index bdbb39180f..b5eff55e9b 100644
--- a/src/test/regress/expected/sanity_check.out
+++ b/src/test/regress/expected/sanity_check.out
@@ -9,7 +9,7 @@ VACUUM;
 \a\t
 SELECT relname, relhasindex
    FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
-   WHERE relkind IN ('r', 'P') AND (nspname ~ '^pg_temp_') IS NOT TRUE
+   WHERE relkind IN ('r', 'p') AND (nspname ~ '^pg_temp_') IS NOT TRUE
    ORDER BY relname;
 a|f
 a_star|f
diff --git a/src/test/regress/sql/sanity_check.sql b/src/test/regress/sql/sanity_check.sql
index fa3a90ff11..04aee457dd 100644
--- a/src/test/regress/sql/sanity_check.sql
+++ b/src/test/regress/sql/sanity_check.sql
@@ -12,7 +12,7 @@ VACUUM;
 
 SELECT relname, relhasindex
    FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
-   WHERE relkind IN ('r', 'P') AND (nspname ~ '^pg_temp_') IS NOT TRUE
+   WHERE relkind IN ('r', 'p') AND (nspname ~ '^pg_temp_') IS NOT TRUE
    ORDER BY relname;
 
 -- restore normal output mode
-- 
2.11.0

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#6)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

I wrote:

Robert Haas <robertmhaas@gmail.com> writes:

For reasons which must've seemed good to whoever instituted the
policy, pg_dump refers to relkinds using the bare letters rather than
the constants.

Even in pg_dump, it appears to me that the large majority of relkind
references use the symbolic names.

After further study, I think it was psql/describe.c you were remembering.
I cleaned that up...

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#9Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#1)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

Tom Lane wrote:

(And no, I don't especially
approve of RELKIND_SEQUENCE being 'S' either, but it's far too late to
change that.)

FWIW the reason SEQUENCE uses S instead of 's' is that the latter was
taken for "special" relations, which we removed a few releases ago
(commit 3a694bb0a1).

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#10Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#9)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

Tom Lane wrote:

(And no, I don't especially
approve of RELKIND_SEQUENCE being 'S' either, but it's far too late to
change that.)

FWIW the reason SEQUENCE uses S instead of 's' is that the latter was
taken for "special" relations, which we removed a few releases ago
(commit 3a694bb0a1).

Yeah, I'd just been reminded of that by some code in describe.c.
So there actually is a reason for sequences to be 'S', or once was.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#11Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#3)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

I wrote:

Robert Haas <robertmhaas@gmail.com> writes:

On Tue, Mar 7, 2017 at 12:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Is there a good reason why RELKIND_PARTITIONED_TABLE is 'P' not 'p'?

I can't muster a lot of outrage about this one way or another. One
possible advantage of 'P' is that there are fewer places where 'P' is
mentioned in the source code than 'p'.

Hm, one would hope that the vast majority of code references are neither
of those, but rather "RELKIND_PARTITIONED_TABLE". information_schema.sql
and system_views.sql will need to be gone over carefully, certainly, but
we shouldn't be hard-coding this anywhere that there's a reasonable
alternative.

Pushed. I was a bit disappointed to find that make check-world passed
just fine without having updated either information_schema.sql or
system_views.sql. Evidently our test coverage for these views leaves
something to be desired.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#12Bruce Momjian
bruce@momjian.us
In reply to: Alvaro Herrera (#9)
Re: Bizarre choice of case for RELKIND_PARTITIONED_TABLE

On Thu, Mar 9, 2017 at 11:06:56PM -0300, Alvaro Herrera wrote:

Tom Lane wrote:

(And no, I don't especially
approve of RELKIND_SEQUENCE being 'S' either, but it's far too late to
change that.)

FWIW the reason SEQUENCE uses S instead of 's' is that the latter was
taken for "special" relations, which we removed a few releases ago
(commit 3a694bb0a1).

Ah! I knew there was a reason for 'S', but couldn't remember it. :-)

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers