From a18d1948d845f1a7b6a3603543d0b951f93b5839 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Tue, 23 Jul 2019 10:08:59 +0200
Subject: [PATCH] Fix properties query for Greenplum

The query projected a column from pg_catalog.pg_class but didn't
include it in the FROM clause. Fix by adding a LEFT OUTER JOIN on
the catalog relation and also promote typname to a projection as
it might be available.

Fixes https://redmine.postgresql.org/issues/4179
---
 .../schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql
index c690a1b8..ca7231ac 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_5.0_plus/properties.sql
@@ -59,7 +59,7 @@ FROM (
 		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age,
 		array_to_string(rel.reloptions, ',') AS table_vacuum_settings_str,
 		array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str,
-		rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, NULL AS reloftype, NULL AS typname,
+		rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, NULL AS reloftype, typ.typname AS typname,
 		typ.typrelid AS typoid,
 		(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
 			-- Added for pgAdmin4
@@ -79,6 +79,7 @@ FROM (
 		LEFT OUTER JOIN pg_constraint con ON con.conrelid=rel.oid AND con.contype='p'
 		LEFT OUTER JOIN pg_class tst ON tst.oid = rel.reltoastrelid
 		LEFT OUTER JOIN gp_distribution_policy gdp ON gdp.localoid = rel.oid
+		LEFT OUTER JOIN pg_type typ ON typ.oid = rel.reltype
 
 	 WHERE rel.relkind IN ('r','s','t') AND rel.relnamespace = {{ scid }}
 	{% if tid %}  AND rel.oid = {{ tid }}::oid {% endif %}
-- 
2.14.1.145.gb3622a4ee

