From 8b5cb90e6778086550fb1024d44b3dbdfa5b1f19 Mon Sep 17 00:00:00 2001
From: Harald Immerheiser <harald.immerheiser@ruv.de>
Date: Sun, 1 Aug 2021 11:27:16 +0200
Subject: [PATCH 2/2] Added SQL files for Greenplum 6.x

---
 .../sql/gpdb_6.0_plus/get_table_information.sql    |  20 ++
 .../gpdb/sql/gpdb_6.0_plus/get_definition.sql      |  17 +
 .../indexes/sql/gpdb_6.0_plus/column_details.sql   |  25 ++
 .../indexes/sql/gpdb_6.0_plus/get_collations.sql   |   6 +
 .../partitions/sql/gpdb/gpdb_6.0_plus/create.sql   |  67 ++++
 .../partitions/sql/gpdb/gpdb_6.0_plus/nodes.sql    |  50 +++
 .../sql/gpdb/gpdb_6.0_plus/properties.sql          |  86 +++++
 .../templates/tables/sql/gpdb_6.0_plus/acl.sql     |  33 ++
 .../templates/tables/sql/gpdb_6.0_plus/create.sql  | 158 +++++++++
 .../templates/tables/sql/gpdb_6.0_plus/delete.sql  |   1 +
 .../templates/tables/sql/gpdb_6.0_plus/nodes.sql   |  13 +
 .../tables/sql/gpdb_6.0_plus/properties.sql        |  95 ++++++
 .../triggers/sql/gpdb/gpdb_6.0_plus/properties.sql |  22 ++
 .../datatype/sql/gpdb_6.0_plus/get_types.sql       |  25 ++
 .../schemas/gpdb/gpdb_6.0_plus/sql/nodes.sql       |  26 ++
 .../schemas/gpdb/gpdb_6.0_plus/sql/properties.sql  |  57 ++++
 .../templates/schemas/gpdb_6.0_plus/sql/acl.sql    |  23 ++
 .../schemas/gpdb_6.0_plus/sql/properties.sql       |  57 ++++
 .../templates/mviews/gpdb_6.0_plus/sql/acl.sql     |  41 +++
 .../mviews/gpdb_6.0_plus/sql/allowed_privs.json    |   6 +
 .../templates/mviews/gpdb_6.0_plus/sql/create.sql  |  47 +++
 .../templates/mviews/gpdb_6.0_plus/sql/delete.sql  |  13 +
 .../templates/mviews/gpdb_6.0_plus/sql/get_oid.sql |   9 +
 .../mviews/gpdb_6.0_plus/sql/get_schema.sql        |   7 +
 .../mviews/gpdb_6.0_plus/sql/get_view_name.sql     |  11 +
 .../templates/mviews/gpdb_6.0_plus/sql/grant.sql   |   6 +
 .../templates/mviews/gpdb_6.0_plus/sql/nodes.sql   |  13 +
 .../mviews/gpdb_6.0_plus/sql/properties.sql        | 120 +++++++
 .../templates/mviews/gpdb_6.0_plus/sql/refresh.sql |   2 +
 .../templates/mviews/gpdb_6.0_plus/sql/update.sql  | 206 ++++++++++++
 .../templates/mviews/gpdb_6.0_plus/sql/view_id.sql |   6 +
 .../templates/views/gpdb_6.0_plus/sql/acl.sql      |  38 +++
 .../views/gpdb_6.0_plus/sql/allowed_privs.json     |   6 +
 .../templates/views/gpdb_6.0_plus/sql/create.sql   |  23 ++
 .../templates/views/gpdb_6.0_plus/sql/delete.sql   |  13 +
 .../templates/views/gpdb_6.0_plus/sql/get_oid.sql  |   9 +
 .../views/gpdb_6.0_plus/sql/get_schema.sql         |   7 +
 .../templates/views/gpdb_6.0_plus/sql/grant.sql    |   6 +
 .../templates/views/gpdb_6.0_plus/sql/nodes.sql    |  13 +
 .../views/gpdb_6.0_plus/sql/properties.sql         |  68 ++++
 .../templates/views/gpdb_6.0_plus/sql/update.sql   |  75 +++++
 .../templates/views/gpdb_6.0_plus/sql/view_id.sql  |   6 +
 .../depends/gpdb/gpdb_6.0_plus/dependencies.sql    |  46 +++
 .../depends/gpdb/gpdb_6.0_plus/dependents.sql      |  45 +++
 .../gpdb/gpdb_6.0_plus/role_dependencies.sql       |   8 +
 .../dashboard/sql/gpdb_6.0_plus/activity.sql       |  19 ++
 .../sql/gpdb_6.0_plus/dashboard_stats.sql          |  62 ++++
 .../search_objects/sql/gpdb/default/search.sql     | 367 +++++++++++++++++++++
 .../sqleditor/sql/gpdb_6.0_plus/explain_plan.sql   |  14 +
 49 files changed, 2093 insertions(+)
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/external_tables/templates/sql/gpdb_6.0_plus/get_table_information.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/functions/gpdb/sql/gpdb_6.0_plus/get_definition.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/gpdb_6.0_plus/column_details.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/gpdb_6.0_plus/get_collations.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/create.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/nodes.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/properties.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/acl.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/create.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/delete.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/nodes.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/properties.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/triggers/sql/gpdb/gpdb_6.0_plus/properties.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/templates/datatype/sql/gpdb_6.0_plus/get_types.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb/gpdb_6.0_plus/sql/nodes.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb/gpdb_6.0_plus/sql/properties.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb_6.0_plus/sql/acl.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb_6.0_plus/sql/properties.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/acl.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/allowed_privs.json
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/create.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/delete.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_oid.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_schema.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_view_name.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/grant.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/nodes.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/properties.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/refresh.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/update.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/view_id.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/acl.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/allowed_privs.json
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/create.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/delete.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/get_oid.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/get_schema.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/grant.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/nodes.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/properties.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/update.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/view_id.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/dependencies.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/dependents.sql
 create mode 100644 web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/role_dependencies.sql
 create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/gpdb_6.0_plus/activity.sql
 create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/gpdb_6.0_plus/dashboard_stats.sql
 create mode 100644 web/pgadmin/tools/search_objects/templates/search_objects/sql/gpdb/default/search.sql
 create mode 100644 web/pgadmin/tools/sqleditor/templates/sqleditor/sql/gpdb_6.0_plus/explain_plan.sql

diff --git a/web/pgadmin/browser/server_groups/servers/databases/external_tables/templates/sql/gpdb_6.0_plus/get_table_information.sql b/web/pgadmin/browser/server_groups/servers/databases/external_tables/templates/sql/gpdb_6.0_plus/get_table_information.sql
new file mode 100644
index 0000000..0f5439c
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/external_tables/templates/sql/gpdb_6.0_plus/get_table_information.sql
@@ -0,0 +1,20 @@
+SELECT x.urilocation, x.execlocation, x.fmttype, x.fmtopts, x.command,
+    x.rejectlimit, x.rejectlimittype,
+    null::text AS errtblname,
+    null::boolean AS errortofile ,
+     pg_catalog.pg_encoding_to_char(x.encoding),
+    x.writable,
+    array_to_string(ARRAY(
+      SELECT pg_catalog.quote_ident(option_name) || ' ' ||
+      pg_catalog.quote_literal(option_value)
+      FROM pg_options_to_table(x.options)
+      ORDER BY option_name
+      ), E',\n    ') AS options,
+    null AS distribution,
+    c.relname AS name,
+    nsp.nspname AS namespace
+FROM pg_catalog.pg_exttable x,
+  pg_catalog.pg_class c
+  LEFT JOIN pg_catalog.pg_namespace nsp ON nsp.oid = c.relnamespace
+  LEFT JOIN gp_distribution_policy gdp ON gdp.localoid = c.oid
+WHERE x.reloid = c.oid AND c.oid = {{ table_oid }}::oid;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/functions/gpdb/sql/gpdb_6.0_plus/get_definition.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/functions/gpdb/sql/gpdb_6.0_plus/get_definition.sql
new file mode 100644
index 0000000..b9b6ca5
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/functions/gpdb/sql/gpdb_6.0_plus/get_definition.sql
@@ -0,0 +1,17 @@
+SELECT proretset, prosrc, probin,
+  pg_catalog.pg_get_function_arguments(pg_proc.oid) AS funcargs,
+  pg_catalog.pg_get_function_identity_arguments(pg_proc.oid) AS funciargs,
+  pg_catalog.pg_get_function_result(pg_proc.oid) AS funcresult,
+  proiswindow proiswin, provolatile, proisstrict, prosecdef,
+  null::text[] AS proconfig, 0::real AS procost, 0::real AS prorows, 'n' AS prodataaccess,
+  'a' as proexeclocation,
+  (SELECT lanname FROM pg_catalog.pg_language WHERE pg_proc.oid = prolang) as lanname,
+  COALESCE(pg_catalog.pg_get_function_identity_arguments(pg_proc.oid), '') AS func_with_identity_arguments,
+  nspname,
+  proname,
+  COALESCE(pg_catalog.pg_get_function_arguments(pg_proc.oid), '') AS func_args
+FROM pg_catalog.pg_proc
+  JOIN pg_namespace nsp ON nsp.oid=pg_proc.pronamespace
+WHERE proisagg = FALSE
+  AND pronamespace = {{scid}}::oid
+  AND pg_proc.oid = {{fnid}}::oid;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/gpdb_6.0_plus/column_details.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/gpdb_6.0_plus/column_details.sql
new file mode 100644
index 0000000..c2b5c75
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/gpdb_6.0_plus/column_details.sql
@@ -0,0 +1,25 @@
+SELECT
+    i.indexrelid,
+    CASE i.indoption[i.attnum - 1]
+    WHEN 0 THEN ARRAY['ASC', 'NULLS LAST']
+    WHEN 1 THEN ARRAY['DESC', 'NULLS FIRST']
+    WHEN 2 THEN ARRAY['ASC', 'NULLS FIRST']
+    WHEN 3 THEN ARRAY['DESC', 'NULLS  ']
+    ELSE ARRAY['UNKNOWN OPTION' || i.indoption[i.attnum - 1]::text, '']
+    END::text[] AS options,
+    i.attnum,
+    pg_get_indexdef(i.indexrelid, i.attnum, true) as attdef,
+    CASE WHEN (o.opcdefault = FALSE) THEN o.opcname ELSE null END AS opcname,
+    NULL AS oprname,
+	  '' AS collnspname
+FROM (
+      SELECT
+          indexrelid, i.indoption, i.indclass,
+          unnest(ARRAY(SELECT generate_series(1, i.indnatts) AS n)) AS attnum
+      FROM
+          pg_index i
+      WHERE i.indexrelid = {{idx}}::OID
+) i
+    LEFT JOIN pg_opclass o ON (o.oid = i.indclass[i.attnum - 1])
+    LEFT JOIN pg_attribute a ON (a.attrelid = i.indexrelid AND a.attnum = i.attnum)
+ORDER BY i.attnum;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/gpdb_6.0_plus/get_collations.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/gpdb_6.0_plus/get_collations.sql
new file mode 100644
index 0000000..a25a02c
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/indexes/sql/gpdb_6.0_plus/get_collations.sql
@@ -0,0 +1,6 @@
+SELECT 'pg_catalog.' || quote_ident(collate_setting.value) AS copy_collation
+FROM (
+       SELECT setting AS value
+       FROM pg_settings
+       WHERE name='lc_collate'
+     ) collate_setting
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/create.sql
new file mode 100644
index 0000000..9ebc6b2
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/create.sql
@@ -0,0 +1,67 @@
+{% import 'tables/sql/macros/constraints.macro' as CONSTRAINTS %}
+{#===========================================#}
+{#====== MAIN TABLE TEMPLATE STARTS HERE ======#}
+{#===========================================#}
+{### CREATE TABLE STATEMENT FOR partitions ###}
+
+CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{% if data.relispartition is defined and data.relispartition %} PARTITION OF {{conn|qtIdent(data.parent_schema, data.partitioned_table_name)}}{% endif %}
+
+{# Macro to render for constraints #}
+{% if data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
+( {% endif %}
+{% if data.primary_key|length > 0 %}{{CONSTRAINTS.PRIMARY_KEY(conn, data.primary_key[0])}}{% endif %}{% if data.unique_constraint|length > 0 %}{% if data.primary_key|length > 0 %},{% endif %}
+{{CONSTRAINTS.UNIQUE(conn, data.unique_constraint)}}{% endif %}{% if data.foreign_key|length > 0 %}{% if data.primary_key|length > 0 or data.unique_constraint|length > 0 %},{% endif %}
+{{CONSTRAINTS.FOREIGN_KEY(conn, data.foreign_key)}}{% endif %}{% if data.check_constraint|length > 0 %}{% if data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 %},{% endif %}
+{{CONSTRAINTS.CHECK(conn, data.check_constraint)}}{% endif %}{% if data.exclude_constraint|length > 0 %}{% if data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 %},{% endif %}
+{{CONSTRAINTS.EXCLUDE(conn, data.exclude_constraint)}}{% endif %}
+{% if data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
+
+)
+{% endif %}
+    {{ data.partition_value }}{% if data.is_partitioned is defined and data.is_partitioned %}
+
+    PARTITION BY {{ data.partition_scheme }}{% endif %}
+{% if data.fillfactor or data.autovacuum_custom or data.autovacuum_enabled in ('t', 'f') or data.toast_autovacuum or data.toast_autovacuum_enabled in ('t', 'f') or (data.autovacuum_enabled in ('t', 'f') and data.vacuum_table|length > 0) or (data.toast_autovacuum_enabled in ('t', 'f') and data.vacuum_toast|length > 0) %}
+{% set ns = namespace(add_comma=false) %}
+
+WITH (
+{% if data.fillfactor %}{% set ns.add_comma = true%}
+    FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.autovacuum_enabled in ('t', 'f') %}
+{% if ns.add_comma %},
+{% endif %}
+    autovacuum_enabled = {% if data.autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %}{% if data.toast_autovacuum_enabled in ('t', 'f') %}
+{% if ns.add_comma %},
+{% endif %}
+    toast.autovacuum_enabled = {% if data.toast_autovacuum_enabled == 't' %}TRUE{% else %}FALSE{% endif %}{% set ns.add_comma = true%}{% endif %}
+{% if data.autovacuum_custom and data.vacuum_table|length > 0 %}
+{% for opt in data.vacuum_table %}{% if opt.name and opt.value is defined %}
+{% if ns.add_comma %},
+{% endif %}
+    {{opt.name}} = {{opt.value}}{% endif %}{% if opt.name and opt.value is defined %}{% set ns.add_comma = true%}{% endif %}
+{% endfor %}{% endif %}
+{% if data.toast_autovacuum and data.vacuum_toast|length > 0 %}
+{% for opt in data.vacuum_toast %}{% if opt.name and opt.value is defined %}
+,
+    toast.{{opt.name}} = {{opt.value}}{% endif %}{% if opt.name and opt.value is defined %}{% set ns.add_comma = true%}{% endif %}
+{% endfor %}{% endif %}
+
+){% endif %}
+{### SQL for Tablespace ###}
+{% if data.spcname %}
+
+TABLESPACE {{ conn|qtIdent(data.spcname) }};
+{% else %}
+;
+
+{% endif %}
+{### Alter SQL for Owner ###}
+{% if data.relowner %}
+
+ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
+    OWNER to {{conn|qtIdent(data.relowner)}};
+{% endif %}
+{### SQL for COMMENT ###}
+{% if data.description %}
+COMMENT ON TABLE {{conn|qtIdent(data.schema, data.name)}}
+    IS {{data.description|qtLiteral}};
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/nodes.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/nodes.sql
new file mode 100644
index 0000000..1a02703
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/nodes.sql
@@ -0,0 +1,50 @@
+SELECT rel.oid, rel.relname AS name,
+    (SELECT count(*) FROM pg_catalog.pg_trigger WHERE tgrelid=rel.oid AND tgisinternal = FALSE) AS triggercount,
+    (SELECT count(*) FROM pg_catalog.pg_trigger WHERE tgrelid=rel.oid AND tgisinternal = FALSE AND tgenabled = 'O') AS has_enable_triggers,
+    pg_get_partition_rule_def(prt.oid, true) AS partition_value,
+    rel.relnamespace AS schema_id,
+    nsp.nspname AS schema_name,
+    (CASE WHEN prt.oid is not null THEN true ELSE false END) AS is_partitioned,
+    false is_sub_partitioned,
+                    CASE
+                    WHEN pp.parkind = 'h'::"char" THEN 'hash'::text
+                    WHEN pp.parkind = 'r'::"char" THEN 'range'::text
+                    WHEN pp.parkind = 'l'::"char" THEN 'list'::text
+                    ELSE NULL::text
+                END AS partition_scheme,
+    '' AS sub_partition_scheme,
+    (CASE WHEN rel.relpersistence = 'u' THEN true ELSE false END) AS relpersistence,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor,
+    (substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS autovacuum_enabled,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_analyze_scale_factor,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS autovacuum_vacuum_cost_delay,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS autovacuum_vacuum_cost_limit,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
+    substring(pg_catalog.array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
+    (substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::BOOL AS toast_autovacuum_enabled,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_analyze_scale_factor,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS toast_autovacuum_vacuum_cost_delay,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS toast_autovacuum_vacuum_cost_limit,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age,
+    substring(pg_catalog.array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age,
+    rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, typ.typname,
+    typ.typrelid AS typoid, des.description, pg_catalog.pg_get_userbyid(rel.relowner) AS relowner
+FROM
+    (SELECT * FROM pg_catalog.pg_inherits WHERE inhparent = {{ tid }}::oid) inh
+    LEFT JOIN pg_catalog.pg_class rel ON inh.inhrelid = rel.oid
+    LEFT JOIN pg_catalog.pg_namespace nsp ON rel.relnamespace = nsp.oid
+    LEFT OUTER JOIN pg_catalog.pg_class tst ON tst.oid = rel.reltoastrelid
+    LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)
+    LEFT JOIN pg_catalog.pg_type typ ON rel.reloftype=typ.oid
+    JOIN pg_catalog.pg_partition_rule prt ON prt.parchildrelid = inh.inhrelid
+    JOIN pg_catalog.pg_partition pp ON prt.paroid = pp.oid
+    {% if ptid %} WHERE rel.oid = {{ ptid }}::OID {% endif %}
+    ORDER BY rel.relname;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/properties.sql
new file mode 100644
index 0000000..c7814b1
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/partitions/sql/gpdb/gpdb_6.0_plus/properties.sql
@@ -0,0 +1,86 @@
+SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS relacl_str,
+  (CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE
+    (SELECT sp.spcname FROM pg_database dtb
+    JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
+    WHERE dtb.oid = {{ did }}::oid)
+  END) as spcname,
+  (select nspname FROM pg_namespace WHERE oid = {{scid}}::oid ) as parent_schema,
+  nsp.nspname as schema,
+  pg_get_userbyid(rel.relowner) AS relowner, rel.relhasoids,
+  (CASE WHEN partitions.number_of_partitions > 0 THEN true ELSE false END) AS relispartition,
+  rel.relhassubclass, rel.reltuples::bigint, des.description, con.conname, con.conkey,
+  EXISTS(select 1 FROM pg_trigger
+		JOIN pg_proc pt ON pt.oid=tgfoid AND pt.proname='logtrigger'
+		JOIN pg_proc pc ON pc.pronamespace=pt.pronamespace AND pc.proname='slonyversion'
+		WHERE tgrelid=rel.oid) AS isrepl,
+					    (SELECT count(*)
+   FROM pg_trigger
+   WHERE tgrelid = rel.oid AND tgconstraint IS NULL) AS triggercount,
+   (SELECT ARRAY(SELECT CASE WHEN (nspname NOT LIKE 'pg\_%') THEN
+            quote_ident(nspname)||'.'||quote_ident(c.relname)
+            ELSE quote_ident(c.relname) END AS inherited_tables
+    FROM pg_inherits i
+    JOIN pg_class c ON c.oid = i.inhparent
+    JOIN pg_namespace n ON n.oid=c.relnamespace
+    WHERE i.inhrelid = rel.oid ORDER BY inhseqno)) AS coll_inherits,
+  (SELECT count(*)
+	FROM pg_inherits i
+      JOIN pg_class c ON c.oid = i.inhparent
+      JOIN pg_namespace n ON n.oid=c.relnamespace
+	WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt,
+  false AS relpersistence,
+  substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor,
+  (CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true')
+    THEN true ELSE false END) AS autovacuum_enabled,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_analyze_scale_factor,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS autovacuum_vacuum_cost_delay,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS autovacuum_vacuum_cost_limit,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
+    substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
+    (CASE WHEN (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') =  'true')
+      THEN true ELSE false END) AS toast_autovacuum_enabled,
+      substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
+      substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor,
+      substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold,
+      substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_analyze_scale_factor,
+      substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS toast_autovacuum_vacuum_cost_delay,
+      substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS toast_autovacuum_vacuum_cost_limit,
+      substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age,
+      substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age,
+      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, rel.reltype, typ.typname,
+      typ.typrelid AS typoid,
+      (CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
+    -- Added for pgAdmin4
+    (CASE WHEN array_length(rel.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom,
+    (CASE WHEN array_length(tst.reloptions, 1) > 0 AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum,
+    NULL AS seclabels,
+    (CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table,
+    -- Added for partition table
+    (CASE WHEN partitions.number_of_partitions > 0 THEN true ELSE false END) AS is_partitioned,
+    '' AS partition_scheme,
+    {% if ptid %}
+      (CASE WHEN partitions.number_of_partitions > 0 THEN partitions.expression ELSE '' END) AS partition_value,
+        (SELECT relname FROM pg_class WHERE oid = {{ tid }}::oid) AS partitioned_table_name
+	{% else %}
+	  partitions.expression AS partition_value
+	  {% endif %}
+
+FROM pg_class rel
+  LEFT OUTER JOIN pg_tablespace spc on spc.oid=rel.reltablespace
+  LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)
+  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 JOIN pg_type typ ON rel.reltype=typ.oid
+  LEFT JOIN pg_inherits inh ON inh.inhrelid = rel.oid
+  LEFT JOIN pg_namespace nsp ON rel.relnamespace = nsp.oid
+  LEFT JOIN (SELECT tablename, partitionboundary as expression, count(*) number_of_partitions FROM pg_partitions GROUP BY tablename, expression) partitions ON rel.relname = tablename
+WHERE inh.inhparent = {{ tid }}::oid
+{% if ptid %}  AND rel.oid = {{ ptid }}::oid {% endif %}
+ORDER BY rel.relname;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/acl.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/acl.sql
new file mode 100644
index 0000000..dd11b33
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/acl.sql
@@ -0,0 +1,33 @@
+{### SQL to fetch privileges for tablespace ###}
+SELECT 'relacl' as deftype, COALESCE(gt.rolname, 'PUBLIC') grantee, g.rolname grantor,
+    array_agg(privilege_type) as privileges, array_agg(is_grantable) as grantable
+FROM
+  (SELECT
+    d.grantee, d.grantor, d.is_grantable,
+    CASE d.privilege_type
+		WHEN 'CONNECT' THEN 'c'
+		WHEN 'CREATE' THEN 'C'
+		WHEN 'DELETE' THEN 'd'
+		WHEN 'EXECUTE' THEN 'X'
+		WHEN 'INSERT' THEN 'a'
+		WHEN 'REFERENCES' THEN 'x'
+		WHEN 'SELECT' THEN 'r'
+		WHEN 'TEMPORARY' THEN 'T'
+		WHEN 'TRIGGER' THEN 't'
+		WHEN 'TRUNCATE' THEN 'D'
+		WHEN 'UPDATE' THEN 'w'
+		WHEN 'USAGE' THEN 'U'
+		ELSE 'UNKNOWN'
+	END AS privilege_type
+  FROM
+    (SELECT (d).grantee AS grantee, (d).grantor AS grantor, (d).is_grantable
+        AS is_grantable, (d).privilege_type AS privilege_type FROM (SELECT
+        aclexplode(rel.relacl) as d
+        FROM pg_class rel
+        WHERE rel.relkind IN ('r','s','t','p') AND rel.relnamespace = {{ scid }}::oid
+            AND rel.oid = {{ tid }}::oid
+        ) a) d
+    ) d
+  LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
+  LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
+GROUP BY g.rolname, gt.rolname
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/create.sql
new file mode 100644
index 0000000..2aa83e2
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/create.sql
@@ -0,0 +1,158 @@
+{% import 'macros/schemas/security.macros' as SECLABEL %}
+{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
+{% import 'macros/variable.macros' as VARIABLE %}
+{% import 'columns/macros/security.macros' as COLUMN_SECLABEL %}
+{% import 'columns/macros/privilege.macros' as COLUMN_PRIVILEGE %}
+{% import 'tables/sql/macros/constraints.macro' as CONSTRAINTS %}
+{% import 'types/macros/get_full_type_sql_format.macros' as GET_TYPE %}
+{#===========================================#}
+{#====== MAIN TABLE TEMPLATE STARTS HERE ======#}
+{#===========================================#}
+{#
+ If user has not provided any details but only name then
+ add empty bracket with table name
+#}
+{% set empty_bracket = ""%}
+{% if data.coll_inherits|length == 0 and  data.columns|length == 0 and not data.typname and not data.like_relation and data.primary_key|length == 0 and data.unique_constraint|length == 0 and data.foreign_key|length == 0 and data.check_constraint|length == 0 and data.exclude_constraint|length == 0 %}
+{% set empty_bracket = "\n(\n)"%}
+{% endif %}
+CREATE {% if data.relpersistence %}UNLOGGED {% endif %}
+{% if data.ext_writeable %}WRITEABLE {% endif %}{% if data.is_external %}EXTERNAL {% if data.ext_command %}WEB {% endif %}{% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{{empty_bracket}}
+{% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
+(
+{% endif %}
+{% if data.like_relation %}
+    LIKE {{ data.like_relation }}{% if data.like_default_value %}
+
+        INCLUDING DEFAULTS{% endif %}{% if data.like_constraints %}
+
+        INCLUDING CONSTRAINTS{% endif %}{% if data.like_indexes %}
+
+        INCLUDING INDEXES{% endif %}{% if data.like_storage %}
+
+        INCLUDING STORAGE{% endif %}{% if data.like_comments %}
+
+        INCLUDING COMMENTS{% endif %}{% if data.columns|length > 0 %},
+{% endif %}
+
+{% endif %}
+{### Add columns ###}
+{% if data.columns and data.columns|length > 0 %}
+{% for c in data.columns %}
+{% if c.name and c.cltype %}
+{% if loop.index != 1 %},
+{% endif %}
+    {{conn|qtIdent(c.name)}} {% if is_sql %}{{c.displaytypname}}{% else %}{{ GET_TYPE.CREATE_TYPE_SQL(conn, c.cltype, c.attlen, c.attprecision, c.hasSqrBracket) }}{% endif %}{% if c.attnotnull %} NOT NULL{% endif %}{% if c.defval %} DEFAULT {{c.defval}}{% endif %}
+{% endif %}
+{% endfor %}
+{% endif %}
+{# Macro to render for constraints #}
+{% if data.primary_key|length > 0 %}{% if data.columns|length > 0 %},{% endif %}
+{{CONSTRAINTS.PRIMARY_KEY(conn, data.primary_key[0])}}{% endif %}{% if data.unique_constraint|length > 0 %}{% if data.columns|length > 0 or data.primary_key|length > 0 %},{% endif %}
+{{CONSTRAINTS.UNIQUE(conn, data.unique_constraint)}}{% endif %}{% if data.foreign_key|length > 0 %}{% if data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 %},{% endif %}
+{{CONSTRAINTS.FOREIGN_KEY(conn, data.foreign_key)}}{% endif %}{% if data.check_constraint|length > 0 %}{% if data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 %},{% endif %}
+{{CONSTRAINTS.CHECK(conn, data.check_constraint)}}{% endif %}{% if data.exclude_constraint|length > 0 %}{% if data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 %},{% endif %}
+{{CONSTRAINTS.EXCLUDE(conn, data.exclude_constraint)}}{% endif %}
+{% if data.like_relation or data.coll_inherits or data.columns|length > 0 or data.primary_key|length > 0 or data.unique_constraint|length > 0 or data.foreign_key|length > 0 or data.check_constraint|length > 0 or data.exclude_constraint|length > 0 %}
+
+){% endif %}
+
+{### If we are inheriting it from another table(s) ###}
+{% if data.coll_inherits %}
+    INHERITS ({% for val in data.coll_inherits %}{% if loop.index != 1 %}, {% endif %}{{val}}{% endfor %})
+{% endif %}{% if data.is_external %}
+{% if data.ext_command %}EXECUTE {{data.ext_command}} ON {{data.ext_exec_location}}{% else %}LOCATION ( {{data.ext_uri_location}} ){% endif %}
+
+FORMAT '{{data.ext_fmttype}}' ( {{data.ext_fmtopts}} )
+ENCODING '{{data.ext_encoding}}'
+{% else %}
+WITH (
+    OIDS = {% if data.relhasoids %}TRUE{% else %}FALSE{% endif %}{% if data.fillfactor %},
+    FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data.appendonly %},
+    APPENDONLY = TRUE{% endif %}{% if data.compresslevel %},
+    COMPRESSLEVEL = {{ data.compresslevel }}{% endif %}{% if data.blocksize %},
+    BLOCKSIZE = {{ data.blocksize }}{% endif %}{% if data.orientation %},
+    ORIENTATION = {{ data.orientation.upper() }}{% endif %}{% if data.compresstype %},
+    COMPRESSTYPE = {{ data.compresstype.upper() }}{% endif %}
+)
+{### SQL for Tablespace ###}
+{% if data.spcname %}
+TABLESPACE {{ conn|qtIdent(data.spcname) }}
+{% endif %}
+{### SQL for Distribution ###}
+{% if data.distributedby %}
+{{ data.distributedby }}
+{% endif %}
+{% if data.is_partitioned %}PARTITION BY {{ data.partition_scheme }}{% endif %}
+{% endif %}
+;
+{### Alter SQL for Owner ###}
+{% if data.relowner %}
+
+ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
+    OWNER to {{conn|qtIdent(data.relowner)}};
+{% endif %}
+{### Security Labels on Table ###}
+{% if data.seclabels and data.seclabels|length > 0 %}
+
+{% for r in data.seclabels %}
+{{ SECLABEL.SET(conn, 'TABLE', data.name, r.provider, r.label, data.schema) }}
+{% endfor %}
+{% endif %}
+{###  ACL on Table ###}
+{% if data.relacl %}
+{% for priv in data.relacl %}
+{{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, data.name, priv.without_grant, priv.with_grant, data.schema) }}
+{% endfor %}
+{% endif %}
+{### SQL for COMMENT ###}
+{% if data.description %}
+COMMENT ON TABLE {{conn|qtIdent(data.schema, data.name)}}
+    IS {{data.description|qtLiteral}};
+{% endif %}
+{#===========================================#}
+{#====== MAIN TABLE TEMPLATE ENDS HERE ======#}
+{#===========================================#}
+{#===========================================#}
+{#  COLUMN SPECIFIC TEMPLATES STARTS HERE    #}
+{#===========================================#}
+{% if data.columns and data.columns|length > 0 %}
+{% for c in data.columns %}
+{% if c.description %}
+
+COMMENT ON COLUMN {{conn|qtIdent(data.schema, data.name, c.name)}}
+    IS {{c.description|qtLiteral}};
+{% endif %}
+{###  Add variables to column ###}
+{% if c.attoptions and c.attoptions|length > 0 %}
+
+ALTER TABLE {{conn|qtIdent(data.schema, data.name)}}
+    {{ VARIABLE.SET(conn, 'COLUMN', c.name, c.attoptions) }}
+{% endif %}
+{###  ACL ###}
+{% if c.attacl and c.attacl|length > 0 %}
+
+{% for priv in c.attacl %}
+    {{ COLUMN_PRIVILEGE.APPLY(conn, data.schema, data.name, c.name, priv.grantee, priv.without_grant, priv.with_grant) }}
+{% endfor %}
+{% endif %}
+{###  Security Lables ###}
+{% if c.seclabels and c.seclabels|length > 0 %}
+
+{% for r in c.seclabels %}
+{{ COLUMN_SECLABEL.APPLY(conn, 'COLUMN',data.schema, data.name, c.name, r.provider, r.label) }}
+{% endfor %}
+{% endif %}
+{% endfor %}
+{% endif %}
+{#===========================================#}
+{#   COLUMN SPECIFIC TEMPLATES ENDS HERE     #}
+{#===========================================#}
+{#======================================#}
+{#   CONSTRAINTS SPECIFIC TEMPLATES     #}
+{#======================================#}
+{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.primary_key)}}
+{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.unique_constraint)}}
+{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.foreign_key)}}
+{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.check_constraint)}}
+{{CONSTRAINTS.CONSTRAINT_COMMENTS(conn, data.schema, data.name, data.exclude_constraint)}}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/delete.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/delete.sql
new file mode 100644
index 0000000..7941427
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/delete.sql
@@ -0,0 +1 @@
+DROP {% if data.is_external %}EXTERNAL {% endif %}TABLE {{conn|qtIdent(data.schema, data.name)}}{% if cascade %} CASCADE{% endif %};
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/nodes.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/nodes.sql
new file mode 100644
index 0000000..0dc6ccf
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/nodes.sql
@@ -0,0 +1,13 @@
+SELECT rel.oid, rel.relname AS name,
+    (SELECT count(*) FROM pg_trigger WHERE tgrelid=rel.oid) AS triggercount,
+    (SELECT count(*) FROM pg_trigger WHERE tgrelid=rel.oid AND tgenabled = 'O') AS has_enable_triggers,
+    (CASE WHEN (SELECT count(*) from pg_partition where parrelid = rel.oid) > 0 THEN true ELSE false END) AS is_partitioned,
+    (SELECT count(1) FROM pg_inherits WHERE inhrelid=rel.oid LIMIT 1) as is_inherits,
+    (SELECT count(1) FROM pg_inherits WHERE inhparent=rel.oid LIMIT 1) as is_inherited
+FROM pg_class rel
+    WHERE rel.relkind IN ('r','s','t') AND rel.relnamespace = {{ scid }}::oid
+      AND rel.relname NOT IN (SELECT partitiontablename FROM pg_partitions)
+    {% if tid %}
+      AND rel.oid = {{tid}}::OID
+    {% endif %}
+    ORDER BY rel.relname;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/properties.sql
new file mode 100644
index 0000000..7f8c9e5
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/gpdb_6.0_plus/properties.sql
@@ -0,0 +1,95 @@
+SELECT *,
+	(CASE when pre_coll_inherits is NULL then ARRAY[]::varchar[] else pre_coll_inherits END) as coll_inherits
+  {% if tid %}, (CASE WHEN is_partitioned THEN (SELECT substring(pg_get_partition_def({{ tid }}::oid, true) from 14)) ELSE '' END) AS partition_scheme {% endif %}
+FROM (
+	SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS relacl_str,
+		(CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE
+			(SELECT sp.spcname FROM pg_database dtb
+			JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
+			WHERE dtb.oid = {{ did }}::oid)
+		END) as spcname,
+		(select nspname FROM pg_namespace WHERE oid = {{scid}}::oid ) as schema,
+		pg_get_userbyid(rel.relowner) AS relowner, rel.relhasoids,
+		rel.relhassubclass, rel.reltuples::bigint, des.description, con.conname, con.conkey,
+		EXISTS(select 1 FROM pg_trigger
+				JOIN pg_proc pt ON pt.oid=tgfoid AND pt.proname='logtrigger'
+				JOIN pg_proc pc ON pc.pronamespace=pt.pronamespace AND pc.proname='slonyversion'
+				WHERE tgrelid=rel.oid) AS isrepl,
+		(SELECT count(*) FROM pg_trigger WHERE tgrelid=rel.oid) AS triggercount,
+		(SELECT ARRAY(SELECT CASE WHEN (nspname NOT LIKE 'pg\_%') THEN
+							quote_ident(nspname)||'.'||quote_ident(c.relname)
+							ELSE quote_ident(c.relname) END AS inherited_tables
+			FROM pg_inherits i
+			JOIN pg_class c ON c.oid = i.inhparent
+			JOIN pg_namespace n ON n.oid=c.relnamespace
+			WHERE i.inhrelid = rel.oid ORDER BY inhseqno)) AS pre_coll_inherits,
+		(SELECT count(*)
+			FROM pg_inherits i
+				JOIN pg_class c ON c.oid = i.inhparent
+				JOIN pg_namespace n ON n.oid=c.relnamespace
+			WHERE i.inhrelid = rel.oid) AS inherited_tables_cnt,
+		false AS relpersistence,
+		substring(array_to_string(rel.reloptions, ',') FROM 'fillfactor=([0-9]*)') AS fillfactor,
+		substring(array_to_string(rel.reloptions, ',') FROM 'compresslevel=([0-9]*)') AS compresslevel,
+		substring(array_to_string(rel.reloptions, ',') FROM 'blocksize=([0-9]*)') AS blocksize,
+		substring(array_to_string(rel.reloptions, ',') FROM 'orientation=(row|column)') AS orientation,
+		substring(array_to_string(rel.reloptions, ',') FROM 'appendonly=(true|false)')::boolean AS appendonly,
+		substring(array_to_string(rel.reloptions, ',') FROM 'compresstype=(zlib|zstd|quicklz|rle_type|none)') AS compresstype,
+		(CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') = 'true')
+			THEN true ELSE false END) AS autovacuum_enabled,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.][0-9]*)') AS autovacuum_vacuum_scale_factor,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.][0-9]*)') AS autovacuum_analyze_scale_factor,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS autovacuum_vacuum_cost_delay,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS autovacuum_vacuum_cost_limit,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
+		substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
+		(CASE WHEN (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)') =  'true')
+			THEN true ELSE false END) AS toast_autovacuum_enabled,
+		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
+		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.][0-9]*)') AS toast_autovacuum_vacuum_scale_factor,
+		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold,
+		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_analyze_scale_factor=([0-9]*[.][0-9]*)') AS toast_autovacuum_analyze_scale_factor,
+		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS toast_autovacuum_vacuum_cost_delay,
+		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS toast_autovacuum_vacuum_cost_limit,
+		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age,
+		substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age,
+		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,
+                typ.typrelid AS typoid,
+		(CASE WHEN rel.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
+			-- Added for pgAdmin4
+		(CASE WHEN (substring(array_to_string(rel.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::boolean  THEN true ELSE false END) AS autovacuum_custom,
+		(CASE WHEN (substring(array_to_string(tst.reloptions, ',') FROM 'autovacuum_enabled=([a-z|0-9]*)'))::boolean  AND rel.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum,
+
+		ARRAY[]::varchar[] AS seclabels,
+		(CASE WHEN rel.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_table,
+
+		pg_get_table_distributedby(rel.oid) AS distributedby,
+    (CASE WHEN (SELECT count(*) from pg_partition where parrelid = rel.oid) > 0 THEN true ELSE false END) AS is_partitioned,
+		rel.relstorage = 'x' as is_external,
+        regexp_replace(array_to_string(ext.execlocation,','),'PER_|TOTAL_SEGS:|_ONLY|_SEGMENTS','') as ext_exec_location,
+        ''''||array_to_string(ext.urilocation,''',''')||'''' as ext_uri_location,
+        CASE WHEN ext.fmttype = 'c' THEN 'csv' ELSE 'text' END as ext_fmttype,
+        ext.fmtopts as ext_fmtopts,
+        quote_literal(ext.command) as ext_command,
+        pg_encoding_to_char(ext.encoding) AS ext_encoding,
+        ext.writable as ext_writeable
+
+
+	FROM pg_class rel
+		LEFT OUTER JOIN pg_tablespace spc on spc.oid=rel.reltablespace
+		LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass)
+		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 pg_exttable ext ON ext.reloid = 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 %}
+) AS TableInformation
+ ORDER BY name
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/triggers/sql/gpdb/gpdb_6.0_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/triggers/sql/gpdb/gpdb_6.0_plus/properties.sql
new file mode 100644
index 0000000..7b124bc
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/triggers/sql/gpdb/gpdb_6.0_plus/properties.sql
@@ -0,0 +1,22 @@
+SELECT t.oid,t.tgname AS name, t.xmin, t.*, relname, CASE WHEN relkind = 'r' THEN TRUE ELSE FALSE END AS parentistable,
+    nspname, des.description, l.lanname, p.prosrc, p.proname AS tfunction,
+    trim(pg_catalog.pg_get_expr(t.tgqual, t.tgrelid),'()') AS whenclause,
+    -- We need to convert tgargs column bytea datatype to array datatype
+    (string_to_array(encode(tgargs, 'escape'), E'\\000')::text[])[1:tgnargs] AS custom_tgargs,
+{% if datlastsysoid %}
+    (CASE WHEN t.oid <= {{ datlastsysoid}}::oid THEN true ElSE false END) AS is_sys_trigger,
+{% endif %}
+    (CASE WHEN tgconstraint != 0::OID THEN true ElSE false END) AS is_constraint_trigger,
+    (CASE WHEN tgenabled = 'O' THEN true ElSE false END) AS is_enable_trigger
+FROM pg_trigger t
+    JOIN pg_class cl ON cl.oid=tgrelid
+    JOIN pg_namespace na ON na.oid=relnamespace
+    LEFT OUTER JOIN pg_description des ON (des.objoid=t.oid AND des.classoid='pg_trigger'::regclass)
+    LEFT OUTER JOIN pg_proc p ON p.oid=t.tgfoid
+    LEFT OUTER JOIN pg_language l ON l.oid=p.prolang
+WHERE NOT tgisinternal
+    AND tgrelid = {{tid}}::OID
+{% if trid %}
+    AND t.oid = {{trid}}::OID
+{% endif %}
+ORDER BY tgname;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/datatype/sql/gpdb_6.0_plus/get_types.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/datatype/sql/gpdb_6.0_plus/get_types.sql
new file mode 100644
index 0000000..beb6c82
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/datatype/sql/gpdb_6.0_plus/get_types.sql
@@ -0,0 +1,25 @@
+SELECT
+    *
+FROM
+    (SELECT
+        format_type(t.oid,NULL) AS typname,
+        CASE WHEN typelem > 0 THEN typelem ELSE t.oid END as elemoid,
+        typlen, typtype, t.oid, nspname,
+        (SELECT COUNT(1) FROM pg_type t2 WHERE t2.typname = t.typname) > 1 AS isdup,
+        CASE WHEN t.typcollation != 0 THEN TRUE ELSE FALSE END AS is_collatable
+    FROM
+        pg_type t
+    JOIN
+        pg_namespace nsp ON typnamespace=nsp.oid
+    WHERE
+        (NOT (typname = 'unknown' AND nspname = 'pg_catalog'))
+    AND
+        {{ condition }}
+{% if add_serials %}
+{# Here we will add serials types manually #}
+    UNION SELECT 'smallserial', 0, 2, 'b', 0, 'pg_catalog', false, false
+    UNION SELECT 'bigserial', 0, 8, 'b', 0, 'pg_catalog', false, false
+    UNION SELECT 'serial', 0, 4, 'b', 0, 'pg_catalog', false, false
+{% endif %}
+    ) AS dummy
+ORDER BY nspname <> 'pg_catalog', nspname <> 'public', nspname, 1
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb/gpdb_6.0_plus/sql/nodes.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb/gpdb_6.0_plus/sql/nodes.sql
new file mode 100644
index 0000000..78c4f1d
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb/gpdb_6.0_plus/sql/nodes.sql
@@ -0,0 +1,26 @@
+{% import 'catalog/pg/macros/catalogs.sql' as CATALOGS %}
+SELECT
+    nsp.oid,
+    nsp.nspname as name,
+    has_schema_privilege(nsp.oid, 'CREATE') as can_create,
+    has_schema_privilege(nsp.oid, 'USAGE') as has_usage
+FROM
+    pg_namespace nsp
+WHERE
+    {% if scid %}
+    nsp.oid={{scid}}::oid AND
+    {% else %}
+    {% if not show_sysobj %}
+    nspname NOT LIKE 'pg!_%' escape '!' AND
+    {% endif %}
+    {% endif %}
+    NOT (
+{{ CATALOGS.LIST('nsp') }}
+    )
+
+    {% if schema_restrictions %}
+        AND
+        nsp.nspname in ({{schema_restrictions}})
+    {% endif %}
+
+ORDER BY nspname;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb/gpdb_6.0_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb/gpdb_6.0_plus/sql/properties.sql
new file mode 100644
index 0000000..eacc48f
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb/gpdb_6.0_plus/sql/properties.sql
@@ -0,0 +1,57 @@
+{% import 'catalog/pg/macros/catalogs.sql' as CATALOGS %}
+SELECT
+    CASE
+    WHEN (nspname LIKE E'pg\\_temp\\_%') THEN 1
+    WHEN (nspname LIKE E'pg\\_%') THEN 0
+    ELSE 3 END AS nsptyp,
+    nsp.nspname AS name,
+    nsp.oid,
+    pg_catalog.array_to_string(nsp.nspacl::text[], ', ') as acl,
+    r.rolname AS namespaceowner, description,
+    pg_catalog.has_schema_privilege(nsp.oid, 'CREATE') AS can_create,
+    {### Default ACL for Tables ###}
+    (SELECT pg_catalog.array_to_string(ARRAY(
+        SELECT pg_catalog.array_to_string(defaclacl::text[], ', ')
+            FROM pg_catalog.pg_default_acl
+        WHERE defaclobjtype = 'r' AND defaclnamespace = nsp.oid
+    ), ', ')) AS tblacl,
+    {### Default ACL for Sequnces ###}
+    (SELECT pg_catalog.array_to_string(ARRAY(
+        SELECT pg_catalog.array_to_string(defaclacl::text[], ', ')
+            FROM pg_catalog.pg_default_acl
+        WHERE defaclobjtype = 'S' AND defaclnamespace = nsp.oid
+    ), ', ')) AS seqacl,
+    {### Default ACL for Functions ###}
+    (SELECT pg_catalog.array_to_string(ARRAY(
+        SELECT pg_catalog.array_to_string(defaclacl::text[], ', ')
+            FROM pg_catalog.pg_default_acl
+        WHERE defaclobjtype = 'f' AND defaclnamespace = nsp.oid
+    ), ', ')) AS funcacl,
+    {### Default ACL for Type ###}
+    (SELECT pg_catalog.array_to_string(ARRAY(
+        SELECT pg_catalog.array_to_string(defaclacl::text[], ', ')
+            FROM pg_catalog.pg_default_acl
+        WHERE defaclobjtype = 'T' AND defaclnamespace = nsp.oid
+    ), ', ')) AS typeacl,
+    (SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=nsp.oid) AS seclabels
+FROM
+    pg_catalog.pg_namespace nsp
+    LEFT OUTER JOIN pg_catalog.pg_description des ON
+        (des.objoid=nsp.oid AND des.classoid='pg_namespace'::regclass)
+    LEFT JOIN pg_catalog.pg_roles r ON (r.oid = nsp.nspowner)
+WHERE
+    {% if scid %}
+    nsp.oid={{scid}}::oid AND
+    {% else %}
+    {% if not show_sysobj %}
+    nspname NOT LIKE E'pg\\_%' AND
+    {% endif %}
+    {% endif %}
+    NOT (
+{{ CATALOGS.LIST('nsp') }}
+    )
+    {% if schema_restrictions %}
+        AND
+        nsp.nspname in ({{schema_restrictions}})
+    {% endif %}
+ORDER BY 1, nspname;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb_6.0_plus/sql/acl.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb_6.0_plus/sql/acl.sql
new file mode 100644
index 0000000..e1e64be
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb_6.0_plus/sql/acl.sql
@@ -0,0 +1,23 @@
+{# Fetch privileges for schema #}
+SELECT
+    'nspacl' as deftype, COALESCE(gt.rolname, 'PUBLIC') AS grantee,
+    g.rolname AS grantor, array_agg(b.privilege_type) AS privileges,
+    array_agg(b.is_grantable) AS grantable
+FROM
+    (SELECT
+        (d).grantee AS grantee, (d).grantor AS grantor,
+        (d).is_grantable AS is_grantable,
+        CASE (d).privilege_type
+        WHEN 'CREATE' THEN 'C'
+        WHEN 'USAGE' THEN 'U'
+        ELSE 'UNKNOWN - ' || (d).privilege_type
+        END AS privilege_type
+    FROM
+        (SELECT aclexplode(nsp.nspacl) as d
+        FROM pg_namespace nsp
+        WHERE nsp.oid = {{ scid|qtLiteral }}::OID
+        ) a
+    ) b
+    LEFT JOIN pg_catalog.pg_roles g ON (b.grantor = g.oid)
+    LEFT JOIN pg_catalog.pg_roles gt ON (b.grantee = gt.oid)
+GROUP BY g.rolname, gt.rolname;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb_6.0_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb_6.0_plus/sql/properties.sql
new file mode 100644
index 0000000..eacc48f
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/templates/schemas/gpdb_6.0_plus/sql/properties.sql
@@ -0,0 +1,57 @@
+{% import 'catalog/pg/macros/catalogs.sql' as CATALOGS %}
+SELECT
+    CASE
+    WHEN (nspname LIKE E'pg\\_temp\\_%') THEN 1
+    WHEN (nspname LIKE E'pg\\_%') THEN 0
+    ELSE 3 END AS nsptyp,
+    nsp.nspname AS name,
+    nsp.oid,
+    pg_catalog.array_to_string(nsp.nspacl::text[], ', ') as acl,
+    r.rolname AS namespaceowner, description,
+    pg_catalog.has_schema_privilege(nsp.oid, 'CREATE') AS can_create,
+    {### Default ACL for Tables ###}
+    (SELECT pg_catalog.array_to_string(ARRAY(
+        SELECT pg_catalog.array_to_string(defaclacl::text[], ', ')
+            FROM pg_catalog.pg_default_acl
+        WHERE defaclobjtype = 'r' AND defaclnamespace = nsp.oid
+    ), ', ')) AS tblacl,
+    {### Default ACL for Sequnces ###}
+    (SELECT pg_catalog.array_to_string(ARRAY(
+        SELECT pg_catalog.array_to_string(defaclacl::text[], ', ')
+            FROM pg_catalog.pg_default_acl
+        WHERE defaclobjtype = 'S' AND defaclnamespace = nsp.oid
+    ), ', ')) AS seqacl,
+    {### Default ACL for Functions ###}
+    (SELECT pg_catalog.array_to_string(ARRAY(
+        SELECT pg_catalog.array_to_string(defaclacl::text[], ', ')
+            FROM pg_catalog.pg_default_acl
+        WHERE defaclobjtype = 'f' AND defaclnamespace = nsp.oid
+    ), ', ')) AS funcacl,
+    {### Default ACL for Type ###}
+    (SELECT pg_catalog.array_to_string(ARRAY(
+        SELECT pg_catalog.array_to_string(defaclacl::text[], ', ')
+            FROM pg_catalog.pg_default_acl
+        WHERE defaclobjtype = 'T' AND defaclnamespace = nsp.oid
+    ), ', ')) AS typeacl,
+    (SELECT pg_catalog.array_agg(provider || '=' || label) FROM pg_catalog.pg_seclabels sl1 WHERE sl1.objoid=nsp.oid) AS seclabels
+FROM
+    pg_catalog.pg_namespace nsp
+    LEFT OUTER JOIN pg_catalog.pg_description des ON
+        (des.objoid=nsp.oid AND des.classoid='pg_namespace'::regclass)
+    LEFT JOIN pg_catalog.pg_roles r ON (r.oid = nsp.nspowner)
+WHERE
+    {% if scid %}
+    nsp.oid={{scid}}::oid AND
+    {% else %}
+    {% if not show_sysobj %}
+    nspname NOT LIKE E'pg\\_%' AND
+    {% endif %}
+    {% endif %}
+    NOT (
+{{ CATALOGS.LIST('nsp') }}
+    )
+    {% if schema_restrictions %}
+        AND
+        nsp.nspname in ({{schema_restrictions}})
+    {% endif %}
+ORDER BY 1, nspname;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/acl.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/acl.sql
new file mode 100644
index 0000000..6c18f40
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/acl.sql
@@ -0,0 +1,41 @@
+{#============================Get ACLs=========================#}
+{% if vid %}
+SELECT
+    'datacl' as deftype,
+    COALESCE(gt.rolname, 'PUBLIC') grantee,
+    g.rolname grantor,
+    array_agg(privilege_type) as privileges,
+    array_agg(is_grantable) as grantable
+FROM
+    (SELECT
+        d.grantee,
+        d.grantor,
+        d.is_grantable,
+        CASE d.privilege_type
+          WHEN 'DELETE' THEN 'd'
+          WHEN 'INSERT' THEN 'a'
+          WHEN 'REFERENCES' THEN 'x'
+          WHEN 'SELECT' THEN 'r'
+          WHEN 'TRIGGER' THEN 't'
+          WHEN 'UPDATE' THEN 'w'
+          WHEN 'TRUNCATE' THEN 'D'
+          ELSE 'UNKNOWN'
+        END AS privilege_type
+    FROM
+        (SELECT
+            relacl
+         FROM
+            pg_class cl
+         LEFT OUTER JOIN pg_shdescription descr ON
+            (cl.oid=descr.objoid AND descr.classoid='pg_class'::regclass)
+         WHERE
+            cl.oid = {{ vid }}::OID AND relkind = 'm'
+        ) acl,
+        aclexplode(relacl) d
+    ) d
+LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
+LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
+GROUP BY
+    g.rolname,
+    gt.rolname
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/allowed_privs.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/allowed_privs.json
new file mode 100644
index 0000000..f01bb73
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/allowed_privs.json
@@ -0,0 +1,6 @@
+{
+    "datacl": {
+        "type": "MVIEW",
+        "acl": ["a", "r", "w", "d", "D", "x", "t"]
+    }
+}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/create.sql
new file mode 100644
index 0000000..41f9344
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/create.sql
@@ -0,0 +1,47 @@
+{# ===================== Create new view ===================== #}
+{% if display_comments %}
+-- View: {{ conn|qtIdent(data.schema, data.name) }}
+
+-- DROP MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }};
+
+{% endif %}
+{% if data.name and data.schema and data.definition %}
+CREATE MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }}
+{% if(data.fillfactor or data['vacuum_data']|length > 0) %}
+WITH (
+    APPENDONLY = {% if data.appendonly %}TRUE{% else %}FALSE{% endif %}{% if data.compresstype %},
+    COMPRESSTYPE = {{ data.compresstype.upper() }}{% endif %}{% if data.compresslevel %},
+    COMPRESSLEVEL = {{ data.compresslevel }}{% endif %}{% if data.blocksize %},
+    BLOCKSIZE = {{ data.blocksize }}{% endif %}{% if data.orientation %},
+    ORIENTATION = {{ data.orientation.upper() }}{% endif %}{% if data.fillfactor %},
+    FILLFACTOR = {{ data.fillfactor }}{% endif %}{% if data['autovacuum_enabled'] or data['toast_autovacuum_enabled'] or data['vacuum_data']|length > 0 %},{{ '\n' }}{% endif %}
+{% for field in data['vacuum_data'] %}
+{% if field.value is defined and field.value != '' and field.value != none %}
+{% if loop.index > 1 %},
+{% endif %}    {{ field.name }} = {{ field.value|lower }}{% endif %}{% endfor %}
+{{ '\n' }})
+{% endif %}
+{% if data.spcname %}TABLESPACE {{ data.spcname }}
+{% endif %}AS
+{{ data.definition.rstrip(';') }}
+{### SQL for Distribution ###}
+{% if data.with_data %}
+WITH DATA
+{% else %}
+WITH NO DATA
+{% endif %}
+{% if data.distributedby %}
+{{ data.distributedby }}
+{% endif %}
+;
+{% if data.owner %}
+
+ALTER TABLE {{ conn|qtIdent(data.schema, data.name) }}
+    OWNER TO {{ conn|qtIdent(data.owner) }};
+{% endif %}
+{% if data.comment %}
+
+COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }}
+    IS {{ data.comment|qtLiteral }};
+{% endif %}
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/delete.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/delete.sql
new file mode 100644
index 0000000..cf667fc
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/delete.sql
@@ -0,0 +1,13 @@
+{# =================== Drop/Cascade materialized view by name ====================#}
+{% if vid %}
+SELECT
+    c.relname As name,
+    nsp.nspname
+FROM
+    pg_class c
+LEFT JOIN pg_namespace nsp ON c.relnamespace = nsp.oid
+WHERE
+    c.relfilenode = {{ vid }};
+{% elif (name and nspname) %}
+DROP MATERIALIZED VIEW {{ conn|qtIdent(nspname, name) }} {% if cascade %} CASCADE {% endif %}
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_oid.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_oid.sql
new file mode 100644
index 0000000..453c244
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_oid.sql
@@ -0,0 +1,9 @@
+{# ===== fetch new assigned schema id ===== #}
+{% if vid %}
+SELECT
+    c.relnamespace as scid
+FROM
+    pg_class c
+WHERE
+    c.oid = {{vid}}::oid;
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_schema.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_schema.sql
new file mode 100644
index 0000000..bcc3d1c
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_schema.sql
@@ -0,0 +1,7 @@
+{# ===== fetch schema name =====#}
+SELECT
+    nspname
+FROM
+    pg_namespace
+WHERE
+    oid = {{ scid }}::oid;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_view_name.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_view_name.sql
new file mode 100644
index 0000000..29ca638
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/get_view_name.sql
@@ -0,0 +1,11 @@
+{# ===== get view name against view id ==== #}
+{% if vid %}
+SELECT
+    c.relname AS name,
+    nsp.nspname AS schema
+FROM
+    pg_class c
+    LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace
+WHERE
+    c.oid = {{vid}}
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/grant.sql
new file mode 100644
index 0000000..c8228cb
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/grant.sql
@@ -0,0 +1,6 @@
+{# ===== Grant Permissions to User Role on Views/Tables ==== #}
+{% import 'macros/schemas/security.macros' as SECLABEL %}
+{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
+{# We will generate Security Label SQL using macro #}
+{% if data.seclabels %}{% for r in data.seclabels %}{{ SECLABEL.SET(conn, 'MATERIALIZED VIEW', data.name, r.provider, r.label, data.schema) }}{% endfor %}{% endif %}
+{% if data.datacl %}{% for priv in data.datacl %}{{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, data.name, priv.without_grant, priv.with_grant, data.schema) }}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/nodes.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/nodes.sql
new file mode 100644
index 0000000..b6e7373
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/nodes.sql
@@ -0,0 +1,13 @@
+SELECT
+    c.oid,
+    c.relname AS name
+FROM pg_class c
+WHERE
+  c.relkind = 'm'
+{% if (vid and datlastsysoid) %}
+    AND c.oid = {{vid}}::oid
+{% elif scid %}
+    AND c.relnamespace = {{scid}}::oid
+ORDER BY
+    c.relname
+{% endif %}
\ No newline at end of file
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/properties.sql
new file mode 100644
index 0000000..d607951
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/properties.sql
@@ -0,0 +1,120 @@
+{# ========================== Fetch Materialized View Properties ========================= #}
+{% if (vid and datlastsysoid) or scid %}
+SELECT
+    c.oid,
+    c.xmin,
+    c.relname AS name,
+    c.reltablespace AS spcoid,
+    c.relispopulated AS with_data,
+    CASE WHEN length(spcname) > 0 THEN spcname ELSE
+        (SELECT sp.spcname FROM pg_database dtb
+        JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
+        WHERE dtb.oid = {{ did }}::oid)
+    END as spcname,
+    c.relacl,
+    nsp.nspname as schema,
+    pg_get_userbyid(c.relowner) AS owner,
+    description AS comment,
+    pg_get_viewdef(c.oid, true) AS definition,
+    pg_get_table_distributedby(c.oid) AS distributedby,
+    {# ============= Checks if it is system view ================ #}
+    {% if vid and datlastsysoid %}
+    CASE WHEN {{vid}} <= {{datlastsysoid}} THEN True ELSE False END AS system_view,
+    {% endif %}
+    array_to_string(c.relacl::text[], ', ') AS acl,
+    (SELECT array_agg(provider || '=' || label) FROM pg_seclabels sl1 WHERE sl1.objoid=c.oid AND sl1.objsubid=0) AS seclabels,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'fillfactor=([0-9]*)') AS fillfactor,
+		substring(array_to_string(c.reloptions, ',') FROM 'compresslevel=([0-9]*)') AS compresslevel,
+		substring(array_to_string(c.reloptions, ',') FROM 'blocksize=([0-9]*)') AS blocksize,
+		substring(array_to_string(c.reloptions, ',') FROM 'orientation=(row|column)') AS orientation,
+		substring(array_to_string(c.reloptions, ',') FROM 'appendonly=(true|false)')::boolean AS appendonly,
+		substring(array_to_string(c.reloptions, ',') FROM 'compresstype=(zstd|zlib|quicklz|rle_type|none)') AS compresstype,
+    (CASE WHEN (substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_enabled=([a-z|0-9]*)') =  'true') THEN true ELSE false END) AS autovacuum_enabled,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS autovacuum_vacuum_threshold,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_vacuum_scale_factor,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_analyze_threshold=([0-9]*)') AS autovacuum_analyze_threshold,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS autovacuum_analyze_scale_factor,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS autovacuum_vacuum_cost_delay,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS autovacuum_vacuum_cost_limit,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_freeze_min_age=([0-9]*)') AS autovacuum_freeze_min_age,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_freeze_max_age=([0-9]*)') AS autovacuum_freeze_max_age,
+    substring(array_to_string(c.reloptions, ',')
+      FROM 'autovacuum_freeze_table_age=([0-9]*)') AS autovacuum_freeze_table_age,
+    (CASE WHEN (substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_enabled=([a-z|0-9]*)') =  'true') THEN true ELSE false END) AS toast_autovacuum_enabled,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_vacuum_threshold=([0-9]*)') AS toast_autovacuum_vacuum_threshold,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_vacuum_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_vacuum_scale_factor,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_analyze_threshold=([0-9]*)') AS toast_autovacuum_analyze_threshold,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_analyze_scale_factor=([0-9]*[.]?[0-9]*)') AS toast_autovacuum_analyze_scale_factor,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_vacuum_cost_delay=([0-9]*)') AS toast_autovacuum_vacuum_cost_delay,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_vacuum_cost_limit=([0-9]*)') AS toast_autovacuum_vacuum_cost_limit,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_freeze_min_age=([0-9]*)') AS toast_autovacuum_freeze_min_age,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_freeze_max_age=([0-9]*)') AS toast_autovacuum_freeze_max_age,
+    substring(array_to_string(tst.reloptions, ',')
+      FROM 'autovacuum_freeze_table_age=([0-9]*)') AS toast_autovacuum_freeze_table_age,
+    c.reloptions AS reloptions,
+    tst.reloptions AS toast_reloptions,
+    (CASE WHEN c.reltoastrelid = 0 THEN false ELSE true END) AS hastoasttable,
+    (CASE WHEN array_length(c.reloptions, 1) > 0 THEN true ELSE false END) AS autovacuum_custom,
+    (CASE WHEN array_length(tst.reloptions, 1) > 0 AND c.reltoastrelid != 0 THEN true ELSE false END) AS toast_autovacuum
+FROM
+    pg_class c
+LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace
+LEFT OUTER JOIN pg_tablespace spc on spc.oid=c.reltablespace
+LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid and des.objsubid=0 AND des.classoid='pg_class'::regclass)
+LEFT OUTER JOIN pg_class tst ON tst.oid = c.reltoastrelid
+    WHERE ((c.relhasrules AND (EXISTS (
+        SELECT
+            r.rulename
+        FROM
+            pg_rewrite r
+        WHERE
+            ((r.ev_class = c.oid)
+                AND (bpchar(r.ev_type) = '1'::bpchar)) )))
+            AND (c.relkind = 'm'::char)
+          )
+{% if (vid and datlastsysoid) %}
+    AND c.oid = {{vid}}::oid
+{% elif scid %}
+    AND c.relnamespace = {{scid}}::oid
+ORDER BY
+    c.relname
+{% endif %}
+
+{% elif type == 'roles' %}
+SELECT
+    pr.rolname
+FROM
+    pg_roles pr
+WHERE
+    pr.rolcanlogin
+ORDER BY
+    pr.rolname
+
+{% elif type == 'schemas' %}
+SELECT
+    nsp.nspname
+FROM
+    pg_namespace nsp
+WHERE
+    (nsp.nspname NOT LIKE E'pg\\_%'
+        AND nsp.nspname != 'information_schema')
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/refresh.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/refresh.sql
new file mode 100644
index 0000000..a45595f
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/refresh.sql
@@ -0,0 +1,2 @@
+{#= Refresh materialized view =#}
+REFRESH MATERIALIZED VIEW{% if is_concurrent %} CONCURRENTLY{% endif %} {{ conn|qtIdent(nspname, name) }} WITH {% if not with_data %}NO {% endif %}DATA;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/update.sql
new file mode 100644
index 0000000..a728b18
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/update.sql
@@ -0,0 +1,206 @@
+{# ===================== Update View ===================#}
+{% import 'macros/schemas/security.macros' as SECLABEL %}
+{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
+{%- if data -%}
+{% set view_name = data.name if data.name else o_data.name %}
+{% set view_schema = data.schema if data.schema else o_data.schema %}
+{% set def = data.definition.rstrip(';') if data.definition %}
+{# ===== Rename mat view ===== #}
+{% if data.name and data.name != o_data.name %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(o_data.schema, o_data.name) }}
+  RENAME TO {{ conn|qtIdent(data.name) }};
+
+{% endif %}
+{# ===== Alter schema view ===== #}
+{% if data.schema and data.schema != o_data.schema %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(o_data.schema, view_name ) }}
+  SET SCHEMA {{ conn|qtIdent(data.schema) }};
+
+{% endif %}
+{# ===== Alter Table owner ===== #}
+{% if data.owner and data.owner != o_data.owner %}
+ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }}
+  OWNER TO {{ conn|qtIdent(data.owner) }};
+
+{% endif %}
+{# ===== First Drop and then create mat view ===== #}
+{% if def and def != o_data.definition.rstrip(';') %}
+DROP MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }};
+CREATE MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
+{% if data.fillfactor or o_data.fillfactor %}
+WITH(
+{% if data.fillfactor %}
+FILLFACTOR = {{ data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) or (o_data['vacuum_data'] is defined and o_data['vacuum_data']['changed']|length > 0)  %},{% endif %}
+{% elif o_data.fillfactor %}
+FILLFACTOR = {{ o_data.fillfactor }}{% if (data['vacuum_data'] is defined and data['vacuum_data']['changed']|length > 0) or (o_data['vacuum_data'] is defined and o_data['vacuum_data']['changed']|length > 0)  %},{% endif %}
+{% endif %}
+
+{% if data['vacuum_data']['changed']|length > 0 %}
+{% for field in data['vacuum_data']['changed'] %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last  %},{{ '\n' }}{% endif %}
+{% endfor %}
+{% endif %}
+)
+{% endif %}
+ AS
+{{ def }}
+{% if data.with_data is defined %}
+ WITH {{ 'DATA' if data.with_data else 'NO DATA' }};
+{% elif o_data.with_data is defined %}
+ WITH {{ 'DATA' if o_data.with_data else 'NO DATA' }};
+
+{% endif %}
+{% if o_data.comment and not data.comment  %}
+COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
+    IS {{ o_data.comment|qtLiteral }};
+{% endif %}
+{% else %}
+{# ======= Alter Tablespace ========= #}
+{%- if data.spcoid and o_data.spcoid != data.spcoid  -%}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
+  SET TABLESPACE {{ data.spcoid }};
+
+{% endif %}
+{# ======= SET/RESET Fillfactor ========= #}
+{% if data.fillfactor and o_data.fillfactor != data.fillfactor %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
+SET(
+  FILLFACTOR = {{ data.fillfactor }}
+);
+
+{% elif data.fillfactor == '' and o_data.fillfactor|default('', 'true') != data.fillfactor %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
+RESET(
+  FILLFACTOR
+);
+
+{% endif %}
+{# ===== Check for with_data property ===== #}
+{% if data.with_data is defined and o_data.with_data|lower != data.with_data|lower  %}
+REFRESH MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} WITH{{ ' NO' if data.with_data|lower == 'false' else '' }} DATA;
+
+{% endif %}
+{# ===== Check for Table tab properties ===== #}
+{% if ((data.autovacuum_custom is defined and data.autovacuum_custom|lower == 'false') or
+(data.toast_autovacuum is defined and data.toast_autovacuum|lower == 'false')
+) %}
+{% if data.autovacuum_custom|lower == 'false' %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
+  autovacuum_enabled,
+  autovacuum_vacuum_threshold,
+  autovacuum_analyze_threshold,
+  autovacuum_vacuum_scale_factor,
+  autovacuum_analyze_scale_factor,
+  autovacuum_vacuum_cost_delay,
+  autovacuum_vacuum_cost_limit,
+  autovacuum_freeze_min_age,
+  autovacuum_freeze_max_age,
+  autovacuum_freeze_table_age
+);
+
+{% if data.toast_autovacuum is defined and data.toast_autovacuum|lower != 'false' %}
+{% if('vacuum_toast' in data and data['vacuum_toast']['changed']|length > 0) %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET(
+{% for field in data['vacuum_toast']['changed'] %}
+{% if field.value != None %} {{ field.name }} = {{ field.value|lower }}{% if not loop.last  %},{{ '\n' }}{% endif %}
+{% endif %}
+{% endfor %}
+);
+
+{% endif %}
+{% endif %}
+
+{% endif %}
+{% if data.toast_autovacuum|lower == 'false' %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
+  toast.autovacuum_enabled,
+  toast.autovacuum_vacuum_threshold,
+  toast.autovacuum_analyze_threshold,
+  toast.autovacuum_vacuum_scale_factor,
+  toast.autovacuum_analyze_scale_factor,
+  toast.autovacuum_vacuum_cost_delay,
+  toast.autovacuum_vacuum_cost_limit,
+  toast.autovacuum_freeze_min_age,
+  toast.autovacuum_freeze_max_age,
+  toast.autovacuum_freeze_table_age
+);
+
+{% if data.autovacuum_custom is defined and data.autovacuum_custom|lower != 'false' %}
+{% if('vacuum_table' in data and data['vacuum_table']['changed']|length > 0) %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET(
+{% for field in data['vacuum_table']['changed'] %}
+{% if field.value != None %}  {{ field.name }} = {{ field.value|lower }}{% if not loop.last  %},{% endif %}{% endif %}
+{% endfor %}
+);
+
+{% endif %}
+{% endif %}
+{% endif %}{#-- toast_endif ends --#}
+
+{% else %}
+{% if data['vacuum_data']['reset']|length == 0 and
+data['vacuum_data']['changed']|length == 0 and data['settings']|length > 0 %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} SET(
+{% for field in data['settings'] %} {{ field }} = {{ data['settings'][field]|lower }}{% if not loop.last  %},{{ '\n' }}{% endif %}
+{% endfor %}
+);
+
+{% endif %}
+{% if(data['vacuum_data']['changed']|length > 0) %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(data.schema, data.name) }} SET(
+{% for field in data['vacuum_data']['changed'] %}
+{% if field.value != None %}  {{ field.name }} = {{ field.value|lower }}{% if not loop.last  %},{% endif %}{{ '\n' }}{% endif %}
+{% endfor %}
+);
+{% endif %}
+{% if data['vacuum_data']['reset']|length > 0 %}
+ALTER MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }} RESET(
+{% for field in data['vacuum_data']['reset'] %}  {{ field.name }}{% if not loop.last  %},{% endif %}{{ '\n' }}{% endfor %}
+);
+{% endif %}
+{% endif %}{# ===== End check for custom autovacuum ===== #}
+{% endif %}{# ===== End block for check data definition ===== #}
+{% set old_comment = o_data.comment|default('', true) %}
+{% if (data.comment is defined and (data.comment != old_comment)) %}
+
+COMMENT ON MATERIALIZED VIEW {{ conn|qtIdent(view_schema, view_name) }}
+  IS {{ data.comment|qtLiteral }};
+{% endif %}
+{# ============= The SQL generated below will change privileges ============= #}
+{% if data.datacl %}
+{% if 'deleted' in data.datacl %}
+{% for priv in data.datacl.deleted %}
+{{ PRIVILEGE.UNSETALL(conn, 'TABLE', priv.grantee, data.name, data.schema) }}
+{% endfor %}
+{% endif %}
+{% if 'changed' in data.datacl %}
+{% for priv in data.datacl.changed -%}
+{{ PRIVILEGE.UNSETALL(conn, 'TABLE', priv.grantee, data.name, data.schema) }}
+{{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, data.name, priv.without_grant, priv.with_grant, data.schema) }}
+{%- endfor %}
+{% endif %}
+{% if 'added' in data.datacl %}
+{% for priv in data.datacl.added %}
+{{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, data.name, priv.without_grant, priv.with_grant, data.schema) }}
+{% endfor %}
+{% endif %}
+{% endif %}
+{# ============== The SQL generated below will change Security Label ========= #}
+{% if data.seclabels is not none and data.seclabels|length > 0 %}
+{% set seclabels = data.seclabels %}
+{% if 'deleted' in seclabels and seclabels.deleted|length > 0 %}
+{% for r in seclabels.deleted %}
+{{ SECLABEL.UNSET(conn, 'MATERIALIZED VIEW', data.name, r.provider, data.schema) }}
+{% endfor %}
+{% endif %}
+{% if 'added' in seclabels and seclabels.added|length > 0 %}
+{% for r in seclabels.added %}
+{{ SECLABEL.SET(conn, 'MATERIALIZED VIEW', data.name, r.provider, r.label, data.schema) }}
+{% endfor %}
+{% endif %}
+{% if 'changed' in seclabels and seclabels.changed|length > 0 %}
+{% for r in seclabels.changed %}
+{{ SECLABEL.SET(conn, 'MATERIALIZED VIEW', data.name, r.provider, r.label, data.schema) }}
+{% endfor %}
+{% endif %}
+{% endif %}
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/view_id.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/view_id.sql
new file mode 100644
index 0000000..b9d053b
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/mviews/gpdb_6.0_plus/sql/view_id.sql
@@ -0,0 +1,6 @@
+{# ===== Below will provide view id for last created view ==== #}
+{% if data %}
+SELECT c.oid, c.relname FROM pg_class c
+LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace
+WHERE c.relname = {{ data.name|qtLiteral }} and nsp.nspname = {{ data.schema|qtLiteral }};
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/acl.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/acl.sql
new file mode 100644
index 0000000..5993f54
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/acl.sql
@@ -0,0 +1,38 @@
+{# ============================ Get ACLs ========================= #}
+{% if vid %}
+SELECT
+    'datacl' as deftype,
+    COALESCE(gt.rolname, 'PUBLIC') grantee,
+    g.rolname grantor,
+    array_agg(privilege_type) as privileges,
+    array_agg(is_grantable) as grantable
+FROM
+    (SELECT
+        d.grantee, d.grantor, d.is_grantable,
+        CASE d.privilege_type
+        WHEN 'DELETE' THEN 'd'
+        WHEN 'INSERT' THEN 'a'
+        WHEN 'REFERENCES' THEN 'x'
+        WHEN 'SELECT' THEN 'r'
+        WHEN 'TRIGGER' THEN 't'
+        WHEN 'UPDATE' THEN 'w'
+        WHEN 'TRUNCATE' THEN 'D'
+        ELSE 'UNKNOWN'
+        END AS privilege_type
+    FROM
+        (SELECT
+            relacl
+        FROM
+            pg_class cl
+        LEFT OUTER JOIN pg_shdescription descr ON (
+            cl.oid=descr.objoid AND descr.classoid='pg_class'::regclass)
+        WHERE cl.oid = {{ vid }}::OID AND relkind = 'v'
+        ) acl,
+        aclexplode(relacl) d
+    ) d
+LEFT JOIN pg_catalog.pg_roles g ON (d.grantor = g.oid)
+LEFT JOIN pg_catalog.pg_roles gt ON (d.grantee = gt.oid)
+GROUP BY
+    g.rolname,
+    gt.rolname
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/allowed_privs.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/allowed_privs.json
new file mode 100644
index 0000000..71f317f
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/allowed_privs.json
@@ -0,0 +1,6 @@
+{
+    "datacl": {
+        "type": "VIEW",
+        "acl": ["a", "r", "w", "d", "D", "x", "t"]
+    }
+}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/create.sql
new file mode 100644
index 0000000..e5068b2
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/create.sql
@@ -0,0 +1,23 @@
+{#============================Create new view=========================#}
+{% if display_comments %}
+-- View: {{ conn|qtIdent(data.schema, data.name) }}
+
+-- DROP VIEW {{ conn|qtIdent(data.schema, data.name) }};
+
+{% endif %}
+{% if data.name and data.schema and data.definition %}
+CREATE OR REPLACE VIEW {{ conn|qtIdent(data.schema, data.name) }}{% if (data.security_barrier) %}
+WITH (
+{% if data.security_barrier %}    security_barrier={{ data.security_barrier|lower }}{% endif %}
+){% endif %} AS
+{{ data.definition.rstrip(';') }};
+{% if data.owner %}
+
+ALTER TABLE {{ conn|qtIdent(data.schema, data.name) }}
+    OWNER TO {{ conn|qtIdent(data.owner) }};
+{% endif %}
+{% if data.comment %}
+COMMENT ON VIEW {{ conn|qtIdent(data.schema, data.name) }}
+    IS {{ data.comment|qtLiteral }};
+{% endif %}
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/delete.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/delete.sql
new file mode 100644
index 0000000..b1c173f
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/delete.sql
@@ -0,0 +1,13 @@
+{# ====================== Drop/Cascade view by name ===================== #}
+{% if vid %}
+SELECT
+    c.relname AS name,
+    nsp.nspname
+FROM
+    pg_class c
+LEFT JOIN pg_namespace nsp ON c.relnamespace = nsp.oid
+WHERE
+    c.relfilenode = {{ vid }};
+{% elif (name and nspname) %}
+DROP VIEW {{ conn|qtIdent(nspname, name) }} {% if cascade %} CASCADE {% endif %};
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/get_oid.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/get_oid.sql
new file mode 100644
index 0000000..453c244
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/get_oid.sql
@@ -0,0 +1,9 @@
+{# ===== fetch new assigned schema id ===== #}
+{% if vid %}
+SELECT
+    c.relnamespace as scid
+FROM
+    pg_class c
+WHERE
+    c.oid = {{vid}}::oid;
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/get_schema.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/get_schema.sql
new file mode 100644
index 0000000..3bdb5dc
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/get_schema.sql
@@ -0,0 +1,7 @@
+{# ===== fetch schema name against schema oid ===== #}
+SELECT
+    nspname
+FROM
+    pg_namespace
+WHERE
+    oid = {{ scid }}::oid;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/grant.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/grant.sql
new file mode 100644
index 0000000..a7e1585
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/grant.sql
@@ -0,0 +1,6 @@
+{# ===== Grant Permissions to User Role on Views/Tables ===== #}
+{% import 'macros/schemas/security.macros' as SECLABEL %}
+{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
+{# ===== We will generate Security Label SQL using macro ===== #}
+{% if data.seclabels %}{% for r in data.seclabels %}{{ SECLABEL.SET(conn, 'VIEW', data.name, r.provider, r.label, data.schema) }}{{'\r'}}{% endfor %}{{'\r'}}{% endif %}{% if data.datacl %}
+{% for priv in data.datacl %}{{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, data.name, priv.without_grant, priv.with_grant, data.schema) }}{% endfor %}{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/nodes.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/nodes.sql
new file mode 100644
index 0000000..be13396
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/nodes.sql
@@ -0,0 +1,13 @@
+SELECT
+    c.oid,
+    c.relname AS name
+FROM pg_class c
+WHERE
+  c.relkind = 'v'
+{% if (vid and datlastsysoid) %}
+    AND c.oid = {{vid}}::oid
+{% elif scid %}
+    AND c.relnamespace = {{scid}}::oid
+ORDER BY
+    c.relname
+{% endif %}
\ No newline at end of file
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/properties.sql
new file mode 100644
index 0000000..132e1fc
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/properties.sql
@@ -0,0 +1,68 @@
+{% if (vid and datlastsysoid) or scid %}
+SELECT
+    c.oid,
+    c.xmin,
+    c.relkind,
+    description AS comment,
+    (CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE 'pg_default' END) as spcname,
+    c.relname AS name,
+    nsp.nspname AS schema,
+    c.reltablespace AS spcoid,
+    c.relispopulated AS ispopulated,
+    pg_get_userbyid(c.relowner) AS owner,
+    array_to_string(c.relacl::text[], ', ') AS acl,
+    pg_get_viewdef(c.oid, true) AS definition,
+    {# ===== Checks if it is system view ===== #}
+    {% if vid and datlastsysoid %}
+    CASE WHEN {{vid}} <= {{datlastsysoid}} THEN True ELSE False END AS system_view,
+    {% endif %}
+    (SELECT
+        array_agg(provider || '=' || label)
+     FROM
+        pg_seclabels sl1
+     WHERE
+        sl1.objoid=c.oid AND sl1.objsubid=0
+    ) AS seclabels,
+    (substring(array_to_string(c.reloptions, ',')
+        FROM 'security_barrier=([a-z|0-9]*)'))::boolean AS security_barrier
+FROM pg_class c
+LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace
+LEFT OUTER JOIN pg_tablespace spc on spc.oid=c.reltablespace
+LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid and des.objsubid=0 AND des.classoid='pg_class'::regclass)
+    WHERE ((c.relhasrules AND (EXISTS (
+        SELECT
+            r.rulename
+        FROM
+            pg_rewrite r
+        WHERE
+            ((r.ev_class = c.oid)
+                AND (bpchar(r.ev_type) = '1'::bpchar)) )))
+            AND (c.relkind = 'v'::char)
+          )
+{% if (vid and datlastsysoid) %}
+    AND c.oid = {{vid}}::oid
+{% elif scid %}
+    AND c.relnamespace = {{scid}}::oid
+ORDER BY
+    c.relname
+{% endif %}
+
+{% elif type == 'roles' %}
+SELECT
+    pr.rolname
+FROM
+    pg_roles pr
+WHERE
+    pr.rolcanlogin
+ORDER BY
+    pr.rolname
+
+{% elif type == 'schemas' %}
+SELECT
+    nsp.nspname
+FROM
+    pg_namespace nsp
+WHERE
+    (nsp.nspname NOT LIKE E'pg\\_%'
+        AND nsp.nspname != 'information_schema')
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/update.sql
new file mode 100644
index 0000000..d49f7fb
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/update.sql
@@ -0,0 +1,75 @@
+{# ============================ Update View ========================= #}
+{% import 'macros/schemas/security.macros' as SECLABEL %}
+{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
+{% if data %}
+{% set view_name = data.name if data.name else o_data.name %}
+{% set view_schema = data.schema if data.schema else o_data.schema %}
+{% set def = data.definition.rstrip(';') if data.definition %}
+{% if data.name and data.name != o_data.name %}
+ALTER VIEW {{ conn|qtIdent(o_data.schema, o_data.name) }}
+    RENAME TO {{ conn|qtIdent(data.name) }};
+{% endif %}
+{% if data.schema and data.schema != o_data.schema %}
+ALTER VIEW {{ conn|qtIdent(o_data.schema, view_name ) }}
+    SET SCHEMA {{ conn|qtIdent(data.schema) }};
+{% endif %}
+{% if data.owner and data.owner != o_data.owner %}
+ALTER TABLE {{ conn|qtIdent(view_schema, view_name) }}
+    OWNER TO {{ conn|qtIdent(data.owner) }};
+{% endif %}
+{% if def and def != o_data.definition.rstrip(';') %}
+CREATE OR REPLACE VIEW {{ conn|qtIdent(view_schema, view_name) }}
+    WITH (security_barrier={{ data.security_barrier|lower if data.security_barrier is defined else o_data.security_barrier|default('false', 'true')|lower }})
+    AS
+    {{ def }};
+{% else %}
+{% if (data.security_barrier is defined and data.security_barrier|lower !=  o_data.security_barrier|lower) %}
+ALTER VIEW {{ conn|qtIdent(view_schema, view_name) }}
+    SET (security_barrier={{ data.security_barrier|lower }});
+{% endif %}
+{% endif %}
+{% set old_comment = o_data.comment|default('', true) %}
+{% if (data.comment is defined and (data.comment != old_comment)) %}
+
+COMMENT ON VIEW {{ conn|qtIdent(view_schema, view_name) }}
+    IS {{ data.comment|qtLiteral }};
+{% endif %}
+{# The SQL generated below will change privileges #}
+{% if data.datacl %}
+{% if 'deleted' in data.datacl %}
+{% for priv in data.datacl.deleted %}
+{{ PRIVILEGE.UNSETALL(conn, 'TABLE', priv.grantee, data.name, data.schema) }}
+{% endfor %}
+{% endif %}
+{% if 'changed' in data.datacl %}
+{% for priv in data.datacl.changed %}
+{{ PRIVILEGE.UNSETALL(conn, 'TABLE', priv.grantee, data.name, data.schema) }}
+{{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, data.name, priv.without_grant, priv.with_grant, data.schema) }}
+{% endfor %}
+{% endif %}
+{% if 'added' in data.datacl %}
+{% for priv in data.datacl.added %}
+{{ PRIVILEGE.SET(conn, 'TABLE', priv.grantee, data.name, priv.without_grant, priv.with_grant, data.schema) }}
+{% endfor %}
+{% endif %}
+{% endif %}
+{# The SQL generated below will change Security Label #}
+{% if data.seclabels is not none and data.seclabels|length > 0 %}
+{% set seclabels = data.seclabels %}
+{% if 'deleted' in seclabels and seclabels.deleted|length > 0 %}
+{% for r in seclabels.deleted %}
+{{ SECLABEL.UNSET(conn, 'VIEW', data.name, r.provider, data.schema) }}
+{% endfor %}
+{% endif %}
+{% if 'added' in seclabels and seclabels.added|length > 0 %}
+{% for r in seclabels.added %}
+{{ SECLABEL.SET(conn, 'VIEW', data.name, r.provider, r.label, data.schema) }}
+{% endfor %}
+{% endif %}
+{% if 'changed' in seclabels and seclabels.changed|length > 0 %}
+{% for r in seclabels.changed %}
+{{ SECLABEL.SET(conn, 'VIEW', data.name, r.provider, r.label, data.schema) }}
+{% endfor %}
+{% endif %}
+{% endif %}
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/view_id.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/view_id.sql
new file mode 100644
index 0000000..4916e09
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/views/templates/views/gpdb_6.0_plus/sql/view_id.sql
@@ -0,0 +1,6 @@
+{# ===== Below will provide view id for last created view ===== #}
+{% if data %}
+SELECT c.oid, c.relname FROM pg_class c
+LEFT OUTER JOIN pg_namespace nsp on nsp.oid = c.relnamespace
+WHERE c.relname = {{ data.name |qtLiteral }} and nsp.nspname = '{{ data.schema }}';
+{% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/dependencies.sql b/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/dependencies.sql
new file mode 100644
index 0000000..a22a175
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/dependencies.sql
@@ -0,0 +1,46 @@
+SET LOCAL join_collapse_limit=8;
+SELECT DISTINCT dep.deptype, dep.refclassid, cl.relkind, ad.adbin, ad.adsrc,
+    CASE WHEN cl.relkind IS NOT NULL THEN cl.relkind || COALESCE(dep.refobjsubid::character varying, '')
+        WHEN tg.oid IS NOT NULL THEN 'T'::text
+        WHEN ty.oid IS NOT NULL AND ty.typbasetype = 0 THEN 'y'::text
+        WHEN ty.oid IS NOT NULL AND ty.typbasetype != 0 THEN 'd'::text
+        WHEN ns.oid IS NOT NULL THEN 'n'::text
+        WHEN pr.oid IS NOT NULL THEN 'p'::text
+        WHEN la.oid IS NOT NULL THEN 'l'::text
+        WHEN rw.oid IS NOT NULL THEN 'R'::text
+        WHEN co.oid IS NOT NULL THEN 'C'::text || contype
+        WHEN ad.oid IS NOT NULL THEN 'A'::text
+        WHEN fs.oid IS NOT NULL THEN 'F'::text
+        WHEN fdw.oid IS NOT NULL THEN 'f'::text
+    ELSE ''
+    END AS type,
+    COALESCE(coc.relname, clrw.relname) AS ownertable,
+    CASE WHEN cl.relname IS NOT NULL OR att.attname IS NOT NULL THEN cl.relname || '.' || att.attname
+    ELSE COALESCE(cl.relname, co.conname, pr.proname, tg.tgname, ty.typname, la.lanname, rw.rulename, ns.nspname, fs.srvname, fdw.fdwname)
+    END AS refname,
+    COALESCE(nsc.nspname, nso.nspname, nsp.nspname, nst.nspname, nsrw.nspname) AS nspname
+FROM pg_depend dep
+LEFT JOIN pg_class cl ON dep.refobjid=cl.oid
+LEFT JOIN pg_attribute att ON dep.refobjid=att.attrelid AND dep.refobjsubid=att.attnum
+LEFT JOIN pg_namespace nsc ON cl.relnamespace=nsc.oid
+LEFT JOIN pg_proc pr ON dep.refobjid=pr.oid
+LEFT JOIN pg_namespace nsp ON pr.pronamespace=nsp.oid
+LEFT JOIN pg_trigger tg ON dep.refobjid=tg.oid
+LEFT JOIN pg_type ty ON dep.refobjid=ty.oid
+LEFT JOIN pg_namespace nst ON ty.typnamespace=nst.oid
+LEFT JOIN pg_constraint co ON dep.refobjid=co.oid
+LEFT JOIN pg_class coc ON co.conrelid=coc.oid
+LEFT JOIN pg_namespace nso ON co.connamespace=nso.oid
+LEFT JOIN pg_rewrite rw ON dep.refobjid=rw.oid
+LEFT JOIN pg_class clrw ON clrw.oid=rw.ev_class
+LEFT JOIN pg_namespace nsrw ON clrw.relnamespace=nsrw.oid
+LEFT JOIN pg_language la ON dep.refobjid=la.oid
+LEFT JOIN pg_namespace ns ON dep.refobjid=ns.oid
+LEFT JOIN pg_attrdef ad ON ad.adrelid=att.attrelid AND ad.adnum=att.attnum
+LEFT JOIN pg_foreign_server fs ON fs.oid=dep.refobjid
+LEFT JOIN pg_foreign_data_wrapper fdw ON fdw.oid=dep.refobjid
+{{where_clause}} AND
+refclassid IN ( SELECT oid FROM pg_class WHERE relname IN
+   ('pg_class', 'pg_constraint', 'pg_conversion', 'pg_language', 'pg_proc', 'pg_rewrite', 'pg_namespace',
+   'pg_trigger', 'pg_type', 'pg_attrdef', 'pg_event_trigger', 'pg_foreign_server', 'pg_foreign_data_wrapper'))
+ORDER BY refclassid, cl.relkind
diff --git a/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/dependents.sql b/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/dependents.sql
new file mode 100644
index 0000000..284a951
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/dependents.sql
@@ -0,0 +1,45 @@
+SET LOCAL join_collapse_limit=8;
+SELECT DISTINCT dep.deptype, dep.classid, cl.relkind, ad.adbin, ad.adsrc,
+    CASE WHEN cl.relkind IS NOT NULL THEN cl.relkind || COALESCE(dep.objsubid::text, '')
+        WHEN tg.oid IS NOT NULL THEN 'T'::text
+        WHEN ty.oid IS NOT NULL THEN 'y'::text
+        WHEN ns.oid IS NOT NULL THEN 'n'::text
+        WHEN pr.oid IS NOT NULL THEN 'p'::text
+        WHEN la.oid IS NOT NULL THEN 'l'::text
+        WHEN rw.oid IS NOT NULL THEN 'R'::text
+        WHEN co.oid IS NOT NULL THEN 'C'::text || contype
+        WHEN ad.oid IS NOT NULL THEN 'A'::text
+        WHEN fs.oid IS NOT NULL THEN 'F'::text
+        WHEN fdw.oid IS NOT NULL THEN 'f'::text
+        ELSE ''
+    END AS type,
+    COALESCE(coc.relname, clrw.relname) AS ownertable,
+    CASE WHEN cl.relname IS NOT NULL AND att.attname IS NOT NULL THEN cl.relname || '.' || att.attname
+    ELSE COALESCE(cl.relname, co.conname, pr.proname, tg.tgname, ty.typname, la.lanname, rw.rulename, ns.nspname, fs.srvname, fdw.fdwname)
+    END AS refname,
+    COALESCE(nsc.nspname, nso.nspname, nsp.nspname, nst.nspname, nsrw.nspname) AS nspname
+FROM pg_depend dep
+LEFT JOIN pg_class cl ON dep.objid=cl.oid
+LEFT JOIN pg_attribute att ON dep.objid=att.attrelid AND dep.objsubid=att.attnum
+LEFT JOIN pg_namespace nsc ON cl.relnamespace=nsc.oid
+LEFT JOIN pg_proc pr ON dep.objid=pr.oid
+LEFT JOIN pg_namespace nsp ON pr.pronamespace=nsp.oid
+LEFT JOIN pg_trigger tg ON dep.objid=tg.oid
+LEFT JOIN pg_type ty ON dep.objid=ty.oid
+LEFT JOIN pg_namespace nst ON ty.typnamespace=nst.oid
+LEFT JOIN pg_constraint co ON dep.objid=co.oid
+LEFT JOIN pg_class coc ON co.conrelid=coc.oid
+LEFT JOIN pg_namespace nso ON co.connamespace=nso.oid
+LEFT JOIN pg_rewrite rw ON dep.objid=rw.oid
+LEFT JOIN pg_class clrw ON clrw.oid=rw.ev_class
+LEFT JOIN pg_namespace nsrw ON clrw.relnamespace=nsrw.oid
+LEFT JOIN pg_language la ON dep.objid=la.oid
+LEFT JOIN pg_namespace ns ON dep.objid=ns.oid
+LEFT JOIN pg_attrdef ad ON ad.oid=dep.objid
+LEFT JOIN pg_foreign_server fs ON fs.oid=dep.objid
+LEFT JOIN pg_foreign_data_wrapper fdw ON fdw.oid=dep.objid
+{{where_clause}} AND
+classid IN ( SELECT oid FROM pg_class WHERE relname IN
+   ('pg_class', 'pg_constraint', 'pg_conversion', 'pg_language', 'pg_proc', 'pg_rewrite', 'pg_namespace',
+   'pg_trigger', 'pg_type', 'pg_attrdef', 'pg_event_trigger', 'pg_foreign_server', 'pg_foreign_data_wrapper'))
+ORDER BY classid, cl.relkind
diff --git a/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/role_dependencies.sql b/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/role_dependencies.sql
new file mode 100644
index 0000000..bd225e3
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/templates/depends/gpdb/gpdb_6.0_plus/role_dependencies.sql
@@ -0,0 +1,8 @@
+SELECT rolname AS refname, refclassid, deptype
+FROM pg_shdepend dep
+LEFT JOIN pg_roles r ON refclassid=1260 AND refobjid=r.oid
+{{where_clause}}
+{% if db_name %}
+ AND dep.dbid = (SELECT oid FROM pg_database WHERE datname = {{ db_name|qtLiteral }})
+{% endif %}
+ORDER BY 1
diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/gpdb_6.0_plus/activity.sql b/web/pgadmin/dashboard/templates/dashboard/sql/gpdb_6.0_plus/activity.sql
new file mode 100644
index 0000000..65d6e19
--- /dev/null
+++ b/web/pgadmin/dashboard/templates/dashboard/sql/gpdb_6.0_plus/activity.sql
@@ -0,0 +1,19 @@
+/*pga4dash*/
+SELECT
+    pid,
+    datname,
+    usename,
+    application_name||' :'||sess_id AS application_name,
+    client_addr,
+    pg_catalog.to_char(backend_start, 'YYYY-MM-DD HH24:MI:SS TZ') AS backend_start,
+    state,
+    CASE WHEN waiting THEN '{{ _('yes') }}' ELSE '{{ _('no') }}' END AS waiting,
+    query,
+    pg_catalog.to_char(state_change, 'YYYY-MM-DD HH24:MI:SS TZ') AS state_change,
+    pg_catalog.to_char(query_start, 'YYYY-MM-DD HH24:MI:SS TZ') AS query_start,
+    CASE WHEN state = 'active' THEN ROUND((extract(epoch from now() - query_start) / 60)::numeric, 2) ELSE 0 END AS active_since
+FROM
+    pg_catalog.pg_stat_activity
+{% if did %}WHERE
+    datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = {{ did }}){% endif %}
+ORDER BY pid
diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/gpdb_6.0_plus/dashboard_stats.sql b/web/pgadmin/dashboard/templates/dashboard/sql/gpdb_6.0_plus/dashboard_stats.sql
new file mode 100644
index 0000000..273362c
--- /dev/null
+++ b/web/pgadmin/dashboard/templates/dashboard/sql/gpdb_6.0_plus/dashboard_stats.sql
@@ -0,0 +1,62 @@
+/*pga4dash*/
+{% set add_union = false %}
+{% if 'session_stats' in chart_names %}
+{% set add_union = true %}
+SELECT 'session_stats' AS chart_name, row_to_json(t) AS chart_data
+FROM (
+  SELECT count(*) AS "{{ _('Total') }}",
+         sum(CASE WHEN state = 'active' THEN 1 END) AS "{{ _('Active') }}",
+         sum(CASE WHEN state = 'idle' THEN 1 END)   AS "{{ _('Idle') }}"
+  FROM pg_stat_activity {% if did %} WHERE datid =  {{ did }} {% endif %}
+) t
+{% endif %}
+{% if add_union and 'tps_stats' in chart_names %}
+UNION ALL
+{% endif %}
+{% if 'tps_stats' in chart_names %}
+{% set add_union = true %}
+SELECT 'tps_stats' AS chart_name, row_to_json(t) AS chart_data
+FROM (
+  SELECT sum(xact_commit) + sum(xact_rollback) AS "{{ _('Transactions') }}",
+         sum(xact_commit)   AS "{{ _('Commits') }}",
+         sum(xact_rollback) AS "{{ _('Rollbacks') }}"
+  FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}
+) t
+{% endif %}
+{% if add_union and 'ti_stats' in chart_names %}
+UNION ALL
+{% endif %}
+{% if 'ti_stats' in chart_names %}
+{% set add_union = true %}
+SELECT 'ti_stats' AS chart_name, row_to_json(t) AS chart_data
+FROM (
+  SELECT sum(tup_inserted) AS "{{ _('Inserts') }}",
+         sum(tup_updated)  AS "{{ _('Updates') }}",
+         sum(tup_deleted)  AS "{{ _('Deletes') }}"
+  FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}
+) t
+{% endif %}
+{% if add_union and 'to_stats' in chart_names %}
+UNION ALL
+{% endif %}
+{% if 'to_stats' in chart_names %}
+{% set add_union = true %}
+SELECT 'to_stats' AS chart_name, row_to_json(t) AS chart_data
+FROM (
+  SELECT sum(tup_fetched)  AS "{{ _('Fetched') }}",
+         sum(tup_returned) AS "{{ _('Returned') }}"
+  FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}
+) t
+{% endif %}
+{% if add_union and 'bio_stats' in chart_names %}
+UNION ALL
+{% endif %}
+{% if 'bio_stats' in chart_names %}
+{% set add_union = true %}
+SELECT 'bio_stats' AS chart_name, row_to_json(t) AS chart_data
+FROM (
+  SELECT sum(blks_read) AS "{{ _('Reads') }}",
+         sum(blks_hit)  AS "{{ _('Hits') }}"
+  FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}
+) t
+{% endif %}
diff --git a/web/pgadmin/tools/search_objects/templates/search_objects/sql/gpdb/default/search.sql b/web/pgadmin/tools/search_objects/templates/search_objects/sql/gpdb/default/search.sql
new file mode 100644
index 0000000..06d21ec
--- /dev/null
+++ b/web/pgadmin/tools/search_objects/templates/search_objects/sql/gpdb/default/search.sql
@@ -0,0 +1,367 @@
+{% import 'catalog/pg/macros/catalogs.sql' as CATALOGS %}
+{% set all_obj = false %}
+{% if obj_type == 'all' or obj_type is none %}
+{% set all_obj = true %}
+{% endif %}
+SELECT obj_type, obj_name,
+    pg_catalog.REPLACE(obj_path, '/'||sn.schema_name||'/', '/'||{{ CATALOGS.LABELS_SCHEMACOL('sn.schema_name', _) }}||'/') AS obj_path,
+    schema_name, show_node, other_info,
+    CASE
+        WHEN {{ CATALOGS.IS_CATALOG_SCHEMA('sn.schema_name') }} THEN
+            CASE WHEN {{ CATALOGS.DB_SUPPORT_SCHEMACOL('sn.schema_name') }} THEN 'D' ELSE 'O' END
+        ELSE 'N'
+    END AS catalog_level
+FROM (
+{% if all_obj or obj_type in ['table', 'sequence', 'view', 'mview'] %}
+    SELECT
+    CASE
+        WHEN c.relkind in ('r', 't') THEN 'table'
+        WHEN c.relkind = 'S' THEN 'sequence'
+        WHEN c.relkind = 'v' THEN 'view'
+        WHEN c.relkind = 'm' THEN 'mview'
+        ELSE 'should not happen'
+    END::text AS obj_type, c.relname AS obj_name,
+    ':schema.'|| n.oid || ':/' || n.nspname || '/' ||
+    CASE
+        WHEN c.relkind in ('r', 't') THEN ':table.'
+        WHEN c.relkind = 'S' THEN ':sequence.'
+        WHEN c.relkind = 'v' THEN ':view.'
+        WHEN c.relkind = 'm' THEN ':mview.'
+        ELSE 'should not happen'
+    END || c.oid ||':/' || c.relname AS obj_path, n.nspname AS schema_name,
+    CASE
+        WHEN c.relkind in ('r', 't') THEN {{ show_node_prefs['table'] }}
+        WHEN c.relkind = 'S' THEN {{ show_node_prefs['sequence'] }}
+        WHEN c.relkind = 'v' THEN {{ show_node_prefs['view'] }}
+        WHEN c.relkind = 'm' THEN {{ show_node_prefs['mview'] }}
+        ELSE False
+    END AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_class c
+    LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
+    {% if all_obj %}
+    WHERE c.relkind in ('r','t','S','v','m')
+    {% elif obj_type == 'table' %}
+    WHERE c.relkind  in ('r', 't')
+    {% elif obj_type == 'sequence' %}
+    WHERE c.relkind  = 'S'
+    {% elif obj_type == 'view' %}
+    WHERE c.relkind  = 'v'
+    {% elif obj_type == 'mview' %}
+    WHERE c.relkind  = 'm'
+    {% endif %}
+    AND CASE WHEN c.relkind in ('S', 'm') THEN {{ CATALOGS.DB_SUPPORT('n') }} ELSE true END
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['index'] %}
+    SELECT 'index'::text AS obj_type, cls.relname AS obj_name,
+    ':schema.'|| n.oid || ':/' || n.nspname || '/:table.'|| tab.oid ||':/' || tab.relname || '/:index.'|| cls.oid ||':/' || cls.relname AS obj_path, n.nspname AS schema_name,
+    {{ show_node_prefs['index'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_index idx
+    JOIN pg_catalog.pg_class cls ON cls.oid=indexrelid
+    JOIN pg_catalog.pg_class tab ON tab.oid=indrelid
+    JOIN pg_catalog.pg_namespace n ON n.oid=tab.relnamespace
+    LEFT JOIN pg_catalog.pg_depend dep ON (dep.classid = cls.tableoid AND dep.objid = cls.oid AND dep.refobjsubid = '0' AND dep.refclassid=(SELECT oid FROM pg_class WHERE relname='pg_constraint') AND dep.deptype='i')
+    LEFT OUTER JOIN pg_catalog.pg_constraint con ON (con.tableoid = dep.refclassid AND con.oid = dep.refobjid)
+    LEFT OUTER JOIN pg_catalog.pg_description des ON des.objoid=cls.oid
+    LEFT OUTER JOIN pg_catalog.pg_description desp ON (desp.objoid=con.oid AND desp.objsubid = 0)
+    WHERE contype IS NULL
+    AND {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['trigger_function', 'function'] %}
+    SELECT
+        CASE
+        WHEN t.typname IN ('trigger', 'event_trigger') THEN 'trigger_function'
+        ELSE 'function' END::text AS obj_type, p.proname AS obj_name,
+    ':schema.'|| n.oid || ':/' || n.nspname || '/' || case when t.typname = 'trigger' then ':trigger_function.' else ':function.' end || p.oid ||':/' || p.proname AS obj_path, n.nspname AS schema_name,
+    CASE WHEN t.typname IN ('trigger', 'event_trigger') THEN {{ show_node_prefs['trigger_function'] }} ELSE {{ show_node_prefs['function'] }} END AS show_node,
+    pg_catalog.pg_get_function_identity_arguments(p.oid) AS other_info
+    from pg_catalog.pg_proc p
+    left join pg_catalog.pg_namespace n on p.pronamespace = n.oid
+    left join pg_catalog.pg_type t on p.prorettype = t.oid
+    WHERE ({{ CATALOGS.DB_SUPPORT('n') }})
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['event_trigger'] %}
+    select 'event_trigger'::text AS obj_type, evtname AS obj_name, ':event_trigger.'||oid||':/' || evtname AS obj_path, ''::text AS schema_name,
+    {{ show_node_prefs['index'] }} AS show_node, NULL AS other_info from pg_catalog.pg_event_trigger
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['schema'] %}
+    select 'schema'::text AS obj_type, n.nspname AS obj_name,
+    ':schema.'||n.oid||':/' || n.nspname as obj_path, n.nspname AS schema_name,
+    {{ show_node_prefs['schema'] }} AS show_node, NULL AS other_info from pg_catalog.pg_namespace n
+    where {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['column'] %}
+    select 'column'::text AS obj_type, a.attname AS obj_name,
+    ':schema.'||n.oid||':/' || n.nspname || '/' ||
+    case
+        WHEN t.relkind in ('r', 't') THEN ':table.'
+        WHEN t.relkind = 'v' THEN ':view.'
+        WHEN t.relkind = 'm' THEN ':mview.'
+        else 'should not happen'
+    end || t.oid || ':/' || t.relname || '/:column.'|| a.attnum ||':/' || a.attname AS obj_path, n.nspname AS schema_name,
+    {{ show_node_prefs['column'] }} AS show_node, NULL AS other_info
+    from pg_catalog.pg_attribute a
+    inner join pg_catalog.pg_class t on a.attrelid = t.oid and t.relkind in ('r', 't','v','m')
+    left join pg_catalog.pg_namespace n on t.relnamespace = n.oid where a.attnum > 0
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['constraints', 'check_constraint', 'foreign_key', 'primary_key', 'unique_constraint', 'exclusion_constraint'] %}
+    SELECT
+    CASE
+        WHEN c.contype = 'c' THEN  'check_constraint'
+        WHEN c.contype = 'f' THEN  'foreign_key'
+        WHEN c.contype = 'p' THEN  'primary_key'
+        WHEN c.contype = 'u' THEN  'unique_constraint'
+        WHEN c.contype = 'x' THEN  'exclusion_constraint'
+    END::text AS obj_type,
+    case when tf.relname is null then c.conname else c.conname || ' -> ' || tf.relname end AS obj_name,
+    ':schema.'||n.oid||':/' || n.nspname||'/:table.'|| t.oid || ':/'||t.relname||
+    CASE
+        WHEN c.contype = 'c' THEN  '/:check_constraint.' ||c.oid
+        WHEN c.contype = 'f' THEN  '/:foreign_key.' ||c.oid
+        WHEN c.contype = 'p' THEN  '/:primary_key.' ||c.conindid
+        WHEN c.contype = 'u' THEN  '/:unique_constraint.' ||c.conindid
+        WHEN c.contype = 'x' THEN  '/:exclusion_constraint.' ||c.conindid
+    END ||':/'|| case when tf.relname is null then c.conname else c.conname || ' -> ' || tf.relname end AS obj_path, n.nspname AS schema_name,
+    {{ show_node_prefs['constraints'] }} AS show_node, NULL AS other_info
+    from pg_catalog.pg_constraint c
+    left join pg_catalog.pg_class t on c.conrelid = t.oid
+    left join pg_catalog.pg_class tf on c.confrelid = tf.oid
+    left join pg_catalog.pg_namespace n on t.relnamespace = n.oid
+    where c.contypid = 0
+    {% if obj_type == 'check_constraint' %}
+    AND c.contype = 'c'
+    {% elif obj_type == 'foreign_key' %}
+    AND c.contype = 'f'
+    {% elif obj_type == 'primary_key' %}
+    AND c.contype = 'p'
+    {% elif obj_type == 'unique_constraint' %}
+    AND c.contype = 'u'
+    {% elif obj_type == 'exclusion_constraint' %}
+    AND c.contype = 'x'
+    {% else %}
+    AND c.contype IN  ('c', 'f', 'p', 'u', 'x')
+    {% endif %}
+    AND {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['rule'] %}
+    select 'rule'::text AS obj_type, r.rulename AS obj_name, ':schema.'||n.oid||':/' || n.nspname||
+            case
+                WHEN t.relkind in ('r', 't') THEN '/:table.'
+                when t.relkind = 'v' then '/:view.'
+                else 'should not happen'
+            end || t.oid || ':/' || t.relname ||'/:rule.'||r.oid||':/'|| r.rulename AS obj_path,
+            n.nspname AS schema_name,
+            {{ show_node_prefs['rule'] }} AS show_node, NULL AS other_info
+            from pg_catalog.pg_rewrite r
+    inner join pg_catalog.pg_class t on r.ev_class = t.oid and t.relkind in ('r', 't','v')
+    left join pg_catalog.pg_namespace n on t.relnamespace = n.oid
+    where {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['trigger'] %}
+    select 'trigger'::text AS obj_type, tr.tgname AS obj_name, ':schema.'||n.oid||':/' || n.nspname||
+            case
+                WHEN t.relkind in ('r', 't') THEN '/:table.'
+                when t.relkind = 'v' then '/:view.'
+                else 'should not happen'
+            end || t.oid || ':/' || t.relname || '/:trigger.'|| tr.oid || ':/' || tr.tgname AS obj_path, n.nspname AS schema_name,
+            {{ show_node_prefs['trigger'] }} AS show_node, NULL AS other_info
+            from pg_catalog.pg_trigger tr
+    inner join pg_catalog.pg_class t on tr.tgrelid = t.oid and t.relkind in ('r', 't', 'v')
+    left join pg_catalog.pg_namespace n on t.relnamespace = n.oid
+    where tr.tgisinternal = false
+    and {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['type'] %}
+    SELECT 'type'::text AS obj_type, t.typname AS obj_name, ':schema.'||n.oid||':/' || n.nspname ||
+        '/:type.'|| t.oid ||':/' || t.typname AS obj_path, n.nspname AS schema_name,
+        {{ show_node_prefs['type'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_type t
+    LEFT OUTER JOIN pg_catalog.pg_type e ON e.oid=t.typelem
+    LEFT OUTER JOIN pg_catalog.pg_class ct ON ct.oid=t.typrelid AND ct.relkind <> 'c'
+    LEFT OUTER JOIN pg_catalog.pg_namespace n on t.typnamespace = n.oid
+    WHERE t.typtype != 'd' AND t.typname NOT LIKE E'\\_%'
+    {% if not show_system_objects %}
+        AND ct.oid is NULL
+    {% endif %}
+    AND {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['cast'] %}
+    SELECT 'cast'::text AS obj_type, pg_catalog.format_type(st.oid,NULL) ||'->'|| pg_catalog.format_type(tt.oid,tt.typtypmod) AS obj_name,
+    ':cast.'||ca.oid||':/' || pg_catalog.format_type(st.oid,NULL) ||'->'|| pg_catalog.format_type(tt.oid,tt.typtypmod) AS obj_path, ''::text AS schema_name,
+    {{ show_node_prefs['cast'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_cast ca
+    JOIN pg_catalog.pg_type st ON st.oid=castsource
+    JOIN pg_catalog.pg_type tt ON tt.oid=casttarget
+    {% if not show_system_objects %}
+    WHERE ca.oid > {{last_system_oid}}::OID
+    {% endif %}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['language'] %}
+    SELECT 'language'::text AS obj_type, lanname AS obj_name, ':language.'||lan.oid||':/' || lanname AS obj_path, ''::text AS schema_name,
+    {{ show_node_prefs['language'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_language lan
+    WHERE lanispl IS TRUE
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['fts_configuration'] %}
+    SELECT 'fts_configuration'::text AS obj_type, cfg.cfgname AS obj_name, ':schema.'||n.oid||':/' || n.nspname || '/:fts_configuration.'||cfg.oid||':/' || cfg.cfgname AS obj_path, n.nspname AS schema_name,
+    {{ show_node_prefs['fts_configuration'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_ts_config cfg
+    left join pg_catalog.pg_namespace n on cfg.cfgnamespace = n.oid
+    WHERE {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['fts_dictionary'] %}
+    SELECT 'fts_dictionary'::text AS obj_type, dict.dictname AS obj_name, ':schema.'||ns.oid||':/' || ns.nspname || '/:fts_dictionary.'||dict.oid||':/' || dict.dictname AS obj_path, ns.nspname AS schema_name,
+    {{ show_node_prefs['fts_dictionary'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_ts_dict dict
+    left join pg_catalog.pg_namespace ns on dict.dictnamespace = ns.oid
+    WHERE {{ CATALOGS.DB_SUPPORT('ns') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['fts_parser'] %}
+    SELECT 'fts_parser'::text AS obj_type, prs.prsname AS obj_name, ':schema.'||ns.oid||':/' || ns.nspname || '/:fts_parser.'||prs.oid||':/' || prs.prsname AS obj_path, ns.nspname AS schema_name,
+    {{ show_node_prefs['fts_parser'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_ts_parser prs
+    left join pg_catalog.pg_namespace ns on prs.prsnamespace = ns.oid
+    WHERE {{ CATALOGS.DB_SUPPORT('ns') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['fts_template'] %}
+    SELECT 'fts_template'::text AS obj_type, tmpl.tmplname AS obj_name, ':schema.'||ns.oid||':/' || ns.nspname || '/:fts_template.'||tmpl.oid||':/' || tmpl.tmplname AS obj_path, ns.nspname AS schema_name,
+    {{ show_node_prefs['fts_template'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_ts_template tmpl
+    left join pg_catalog.pg_namespace ns on tmpl.tmplnamespace = ns.oid
+    AND {{ CATALOGS.DB_SUPPORT('ns') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['domain'] %}
+    select 'domain'::text AS obj_type, t.typname AS obj_name, ':schema.'||n.oid||':/' || n.nspname || '/:domain.'||t.oid||':/' || t.typname AS obj_path, n.nspname AS schema_name,
+    {{ show_node_prefs['domain'] }} AS show_node, NULL AS other_info
+    from pg_catalog.pg_type t
+    inner join pg_catalog.pg_namespace n on t.typnamespace = n.oid
+    where t.typtype = 'd'
+    AND {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['domain_constraints'] %}
+    SELECT 'domain_constraints'::text AS obj_type,
+        c.conname AS obj_name, ':schema.'||n.oid||':/' || n.nspname || '/:domain.'||t.oid||':/' || t.typname || '/:domain_constraints.'||c.oid||':/' || c.conname AS obj_path,
+        n.nspname AS schema_name,
+        {{ show_node_prefs['domain_constraints'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_constraint c JOIN pg_catalog.pg_type t
+    ON t.oid=contypid JOIN pg_catalog.pg_namespace n
+    ON n.oid=t.typnamespace
+    WHERE t.typtype = 'd'
+    AND {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['foreign_data_wrapper'] %}
+    select 'foreign_data_wrapper'::text AS obj_type, fdwname AS obj_name, ':foreign_data_wrapper.'||oid||':/' || fdwname AS obj_path, ''::text AS schema_name,
+    {{ show_node_prefs['foreign_data_wrapper'] }} AS show_node, NULL AS other_info
+    from pg_catalog.pg_foreign_data_wrapper
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['foreign_server'] %}
+    select 'foreign_server'::text AS obj_type, sr.srvname AS obj_name, ':foreign_data_wrapper.'||fdw.oid||':/' || fdw.fdwname || '/:foreign_server.'||sr.oid||':/' || sr.srvname AS obj_path, ''::text AS schema_name,
+    {{ show_node_prefs['foreign_server'] }} AS show_node, NULL AS other_info
+    from pg_catalog.pg_foreign_server sr
+    inner join pg_catalog.pg_foreign_data_wrapper fdw on sr.srvfdw = fdw.oid
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['user_mapping'] %}
+    select 'user_mapping'::text AS obj_type, um.usename AS obj_name, ':foreign_data_wrapper.'||fdw.oid||':/' || fdw.fdwname || '/:foreign_server.'||sr.oid||':/' || sr.srvname || '/:user_mapping.'||um.umid||':/' || um.usename AS obj_path, ''::text AS schema_name,
+    {{ show_node_prefs['user_mapping'] }} AS show_node, NULL AS other_info
+    from pg_catalog.pg_user_mappings um
+    inner join pg_catalog.pg_foreign_server sr on um.srvid = sr.oid
+    inner join pg_catalog.pg_foreign_data_wrapper fdw on sr.srvfdw = fdw.oid
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['foreign_table'] %}
+    select 'foreign_table'::text AS obj_type, c.relname AS obj_name, ':schema.'||ns.oid||':/' || ns.nspname || '/:foreign_table.'||c.oid||':/' || c.relname AS obj_path, ns.nspname AS schema_name,
+    {{ show_node_prefs['foreign_table'] }} AS show_node, NULL AS other_info
+    from pg_catalog.pg_foreign_table ft
+    inner join pg_catalog.pg_class c on ft.ftrelid = c.oid
+    inner join pg_catalog.pg_namespace ns on c.relnamespace = ns.oid
+    AND {{ CATALOGS.DB_SUPPORT('ns') }}
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['extension'] %}
+    select 'extension'::text AS obj_type, x.extname AS obj_name, ':extension.'||x.oid||':/' || x.extname AS obj_path, ''::text AS schema_name,
+    {{ show_node_prefs['extension'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_extension x
+    JOIN pg_catalog.pg_namespace n on x.extnamespace=n.oid
+    join pg_catalog.pg_available_extensions() e(name, default_version, comment) ON x.extname=e.name
+{% endif %}
+{% if all_obj %}
+    UNION
+{% endif %}
+{% if all_obj or obj_type in ['collation'] %}
+    SELECT 'collation'::text AS obj_type, c.collname AS obj_name, ':schema.'||n.oid||':/' || n.nspname || '/:collation.'||c.oid||':/' || c.collname AS obj_path, n.nspname AS schema_name,
+    {{ show_node_prefs['collation'] }} AS show_node, NULL AS other_info
+    FROM pg_catalog.pg_collation c
+    JOIN pg_catalog.pg_namespace n ON n.oid=c.collnamespace
+    WHERE {{ CATALOGS.DB_SUPPORT('n') }}
+{% endif %}
+
+) sn
+where lower(sn.obj_name) like '%{{ search_text }}%'
+{% if not show_system_objects %}
+AND NOT ({{ CATALOGS.IS_CATALOG_SCHEMA('sn.schema_name') }})
+AND (sn.schema_name IS NOT NULL AND sn.schema_name NOT LIKE 'pg\_%')
+{% endif %}
+ORDER BY 1, 2, 3
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/gpdb_6.0_plus/explain_plan.sql b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/gpdb_6.0_plus/explain_plan.sql
new file mode 100644
index 0000000..f1bcbeb
--- /dev/null
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/sql/gpdb_6.0_plus/explain_plan.sql
@@ -0,0 +1,14 @@
+{% import 'sql/macros/utils.macros' as UTILS %}
+EXPLAIN ({% if format -%}
+  FORMAT {{ format.upper() }}
+{%- endif %}{% if analyze is defined -%}
+  , ANALYZE {{ UTILS.BOOL_TEXT(analyze) }}
+{%- endif %}{% if verbose is defined -%}
+  , VERBOSE {{ UTILS.BOOL_TEXT(verbose) }}
+{%- endif %}{% if costs is defined -%}
+  , COSTS {{ UTILS.BOOL_TEXT(costs) }}
+{%- endif %}{% if timing is defined -%}
+  , TIMING {{ UTILS.BOOL_TEXT(timing) }}
+{%- endif %}{% if buffers is defined -%}
+  , BUFFERS {{ UTILS.BOOL_TEXT(buffers) }}
+{%- endif %}) {{ sql }}
-- 
2.8.0

