diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/10_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/10_plus/properties.sql index 55b5e482..8bba0afb 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/10_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/10_plus/properties.sql @@ -53,6 +53,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, CASE WHEN typ.typname IS NOT NULL THEN (select quote_ident(nspname) FROM pg_namespace WHERE oid = {{scid}}::oid )||'.'||quote_ident(typ.typname) ELSE typ.typname END 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, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/properties.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/properties.sql index c76c8051..3dc29051 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/properties.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/table/sql/9.1_plus/properties.sql @@ -52,6 +52,7 @@ SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS r array_to_string(tst.reloptions, ',') AS toast_table_vacuum_settings_str, rel.reloptions AS reloptions, tst.reloptions AS toast_reloptions, rel.reloftype, CASE WHEN typ.typname IS NOT NULL THEN (select quote_ident(nspname) FROM pg_namespace WHERE oid = {{scid}}::oid )||'.'||quote_ident(typ.typname) ELSE typ.typname END 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, 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 82501a91..b93cc7ca 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,8 +41,8 @@ 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 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 c.name and c.cltype %} +{% if c.inheritedfromtable %}-- Inherited from table {{c.inheritedfromtable}}:{% elif c.inheritedfromtype %}-- Inherited from type {{c.inheritedfromtype}}:{% 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.collspcname %} COLLATE {{c.collspcname}}{% endif %}{% if c.attnotnull %} NOT NULL{% endif %}{% if c.defval %} DEFAULT {{c.defval}}{% endif %} {% if not loop.last %}, {% endif %} {% endif %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py index 372c4edc..9dbd1fe9 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py @@ -609,20 +609,21 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): # 4) Find all the columns for tables and filter out columns which are # not inherited from any table & format them one by one + other_columns = [] + table_or_type = '' # Get of_type table columns and add it into columns dict - if data['typname']: + if data['typoid']: SQL = render_template("/".join([self.table_template_path, 'get_columns_for_table.sql']), - tname=data['typname']) + tid=data['typoid']) status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) - data['columns'] = res['rows'] - + other_columns = res['rows'] + table_or_type = 'type' # Get inherited table(s) columns and add it into columns dict elif data['coll_inherits'] and len(data['coll_inherits']) > 0: - columns = [] # Return all tables which can be inherited & do not show # system columns SQL = render_template("/".join([self.table_template_path, @@ -645,8 +646,9 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): status, res = self.conn.execute_dict(SQL) if not status: return internal_server_error(errormsg=res) - columns.extend(res['rows'][:]) - data['columns'] = columns + other_columns.extend(res['rows'][:]) + + table_or_type = 'table' # We will fetch all the columns for the table using # columns properties.sql, so we need to set template path @@ -661,24 +663,14 @@ class BaseTableView(PGChildNodeView, BasePartitionTable): return internal_server_error(errormsg=res) all_columns = res['rows'] - # Filter inherited columns from all columns - if 'columns' in data and len(data['columns']) > 0 \ - and len(all_columns) > 0: - for row in data['columns']: - for i, col in enumerate(all_columns): - # If both name are same then remove it - # as it is inherited from other table - if col['name'] == row['name']: - # Remove same column from all_columns as - # already have it columns collection - del all_columns[i] - - # If any column is added then update columns collection - if len(all_columns) > 0: - data['columns'] += all_columns - # If no inherited columns found then add all columns - elif len(all_columns) > 0: - data['columns'] = all_columns + # Add inheritedfrom details from other columns - type, table + for col in all_columns: + for other_col in other_columns: + if col['name'] == other_col['name']: + col['inheritedfrom' + table_or_type] = \ + other_col['inheritedfrom'] + + data['columns'] = all_columns if 'columns' in data and len(data['columns']) > 0: data = self._columns_formatter(tid, data)