Subject: [pgAdmin4][Patch] - RM 3505 Incorrect SQL generated for tables created using inherited columns

From: Akshay Joshi <[email-masked]>
Date: Thu, 10 Jan 2019 14:56:32 +0530

Hi Hackers,

Attached is the patch to fix RM #3505 Incorrect SQL generated for tables
created using inherited columns.

Please review it.

-- 
*Akshay Joshi*

*Sr. Software Architect *

*Phone: +91 20-3058-9517Mobile: +91 976-788-8246*
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/default/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/default/create.sql
index 8ea1b762..82501a91 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/default/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/default/create.sql
@@ -41,10 +41,10 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
 {### 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 %}
+{% if c.name and c.cltype and not c.inheritedfrom %}
     {{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.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.attnotnull %} NOT NULL{% endif %}{% if c.defval %} DEFAULT {{c.defval}}{% endif %}
+{% if not loop.last %},
+{% endif %}
 {% endif %}
 {% endfor %}
 {% endif %}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/default/sql.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/default/sql.sql
deleted file mode 100644
index 17b35aed..00000000
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/default/sql.sql
+++ /dev/null
@@ -1 +0,0 @@
-TAKE ASHESH'S HELP ON THIS TASK :-)
\ No newline at end of file
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/gpdb_5.0_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/gpdb_5.0_plus/create.sql
index 61e4e1e1..c82e72cc 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/gpdb_5.0_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/gpdb_5.0_plus/create.sql
@@ -41,10 +41,10 @@ CREATE {% if data.relpersistence %}UNLOGGED {% endif %}TABLE {{conn|qtIdent(data
 {### 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 %}
+{% if c.name and c.cltype and not c.inheritedfrom %}
     {{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.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.attnotnull %} NOT NULL{% endif %}{% if c.defval %} DEFAULT {{c.defval}}{% endif %}
+{% if not loop.last %},
+{% endif %}
 {% endif %}
 {% endfor %}
 {% endif %}

---

From: Dave Page <[email-masked]>
Date: Fri, 11 Jan 2019 21:50:14 +0530

Thanks, patch applied.

On Thu, Jan 10, 2019 at 2:56 PM Akshay Joshi
<[email-masked]> wrote:
>
> Hi Hackers,
>
> Attached is the patch to fix RM #3505 Incorrect SQL generated for tables created using inherited columns.
>
> Please review it.
>
> --
> Akshay Joshi
> Sr. Software Architect
>
>
> Phone: +91 20-3058-9517
> Mobile: +91 976-788-8246

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company