Fixed issues reported while testing foreign table properties. #640

This commit is contained in:
Yogesh Mahajan 2023-10-11 11:53:14 +05:30 committed by GitHub
parent cd84200135
commit 4450145d31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 62 additions and 6 deletions

View File

@ -1189,7 +1189,8 @@ class ForeignTableView(PGChildNodeView, DataTypeReader,
c['schema'] = data['schema']
c['table'] = data['name']
# Sql for drop column
if 'inheritedfrom' not in c:
if 'inheritedfrom' not in c or \
('inheritedfrom' in c and c['inheritedfrom'] is None):
column_sql += render_template("/".join(
[self.foreign_table_column_template_path,
self._DELETE_SQL]),

View File

@ -11,27 +11,27 @@ ALTER FOREIGN TABLE IF EXISTS {{conn|qtIdent(data.schema, data.table)}}
NOT NULL{% endif %}{% if data.defval is defined and data.defval is not none and data.defval != '' and data.colconstype != 'g' %}
DEFAULT {{data.defval}}{% endif %}{% if data.colconstype == 'g' and data.genexpr and data.genexpr != '' %}
GENERATED ALWAYS AS ({{data.genexpr}}) STORED{% endif %}{% endif %};
{### Add comments ###}
{% if data and data.description and data.description != None %}
COMMENT ON COLUMN {{conn|qtIdent(data.schema, data.table, data.name)}}
IS {{data.description|qtLiteral(conn)}};
{% endif %}
{### Add variables to column ###}
{% if data.attoptions %}
ALTER FOREIGN TABLE IF EXISTS {{conn|qtIdent(data.schema, data.table)}}
{{ VARIABLE.SET(conn, 'COLUMN', data.name, data.attoptions) }}
{% endif %}
{### Alter column statistics value ###}
{% if data.attstattarget is defined and data.attstattarget > -1 %}
ALTER FOREIGN TABLE IF EXISTS {{conn|qtIdent(data.schema, data.table)}}
ALTER COLUMN {{conn|qtTypeIdent(data.name)}} SET STATISTICS {{data.attstattarget}};
{% endif %}
{### Alter column storage value ###}
{% if data.attstorage is defined and data.attstorage != data.defaultstorage %}
ALTER FOREIGN TABLE IF EXISTS {{conn|qtIdent(data.schema, data.table)}}
ALTER COLUMN {{conn|qtTypeIdent(data.name)}} SET STORAGE {%if data.attstorage == 'p' %}
PLAIN{% elif data.attstorage == 'm'%}MAIN{% elif data.attstorage == 'e'%}

View File

@ -1,5 +1,6 @@
{% import 'macros/schemas/security.macros' as SECLABEL %}
{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
{% import 'macros/variable.macros' as VARIABLE %}
{% set is_columns = [] %}
{% if data %}
CREATE FOREIGN TABLE{% if add_not_exists_clause %} IF NOT EXISTS{% endif %} {{ conn|qtIdent(data.basensp, data.name) }}(
@ -12,7 +13,9 @@ CREATE FOREIGN TABLE{% if add_not_exists_clause %} IF NOT EXISTS{% endif %} {{ c
{% if loop.first %} OPTIONS ({% endif %}{% if not loop.first %}, {% endif %}{{o.option}} {{o.value|qtLiteral(conn)}}{% if loop.last %}){% endif %}{% endif %}
{% endfor %}{% endif %}
{% if c.attnotnull %} NOT NULL{% endif %}
{% if c.defval is defined and c.defval is not none %} DEFAULT {{c.defval}}{% endif %}
{% if c.defval is defined and c.defval is not none and c.defval != '' and c.colconstype != 'g' %} DEFAULT {{c.defval}}{% endif %}
{% if c.colconstype == 'g' and c.genexpr and c.genexpr != '' %}
GENERATED ALWAYS AS {{c.genexpr}} STORED{% endif %}
{% if c.collname %} COLLATE {{c.collname}}{% endif %}
{% if not loop.last %},
{% endif %}
@ -71,3 +74,37 @@ COMMENT ON COLUMN {{conn|qtIdent(data.basensp, data.name, c.name)}}
{% endfor %}
{% endif %}
{% endif %}
{#===========================================#}
{# 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(conn)}};
{% endif %}
{### Add variables to column ###}
{% if c.attoptions and c.attoptions|length > 0 %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
{{ VARIABLE.SET(conn, 'COLUMN', c.name, c.attoptions) }}
{% endif %}
{### Alter column statistics value ###}
{% if c.attstattarget is defined and c.attstattarget > -1 %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
ALTER COLUMN {{conn|qtTypeIdent(c.name)}} SET STATISTICS {{c.attstattarget}};
{% endif %}
{### Alter column storage value ###}
{% if c.attstorage is defined and c.attstorage != c.defaultstorage %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
ALTER COLUMN {{conn|qtTypeIdent(c.name)}} SET STORAGE {%if c.attstorage == 'p' %}
PLAIN{% elif c.attstorage == 'm'%}MAIN{% elif c.attstorage == 'e'%}
EXTERNAL{% elif c.attstorage == 'x'%}EXTENDED{% endif %};
{% endif %}
{% endfor %}
{% endif %}

View File

@ -16,6 +16,7 @@ WITH INH_TABLES AS
SELECT INH.inheritedfrom, INH.inheritedid, att.attoptions, att.atttypid, attfdwoptions,
att.attname as name, att.attndims, att.atttypmod, pg_catalog.format_type(t.oid,NULL) AS cltype,
att.attnotnull, att.attstorage, att.attstattarget, att.attnum, pg_catalog.format_type(t.oid, att.atttypmod) AS fulltype,
t.typstorage AS defaultstorage,
CASE WHEN t.typelem > 0 THEN t.typelem ELSE t.oid END as elemoid,
(CASE WHEN (att.attidentity in ('a', 'd')) THEN 'i' WHEN (att.attgenerated in ('s')) THEN 'g' ELSE 'n' END) AS colconstype,
(CASE WHEN (att.attgenerated in ('s')) THEN pg_catalog.pg_get_expr(def.adbin, def.adrelid) END) AS genexpr,

View File

@ -2,6 +2,7 @@ SELECT
c.oid, c.relname AS name, pg_catalog.pg_get_userbyid(relowner) AS owner,
pg_catalog.array_to_string(c.relacl::text[], ', ') as acl,
ftoptions, srvname AS ftsrvname, description, nspname AS basensp,
(SELECT count(*) FROM pg_catalog.pg_trigger WHERE tgrelid=ftrelid AND tgisinternal = FALSE) AS triggercount,
(SELECT
pg_catalog.array_agg(provider || '=' || label)
FROM

View File

@ -20,3 +20,7 @@ COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"
GRANT SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres;
ALTER TABLE IF EXISTS "FT1_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN col1 SET STATISTICS 10;

View File

@ -15,3 +15,7 @@ COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"
IS 'Test Comment';
GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO postgres;
ALTER TABLE IF EXISTS "FT1_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN col1 SET STATISTICS 10;

View File

@ -20,3 +20,7 @@ COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"
GRANT SELECT ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO PUBLIC;
GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb;
ALTER TABLE IF EXISTS "FT1_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN col1 SET STATISTICS 10;

View File

@ -15,3 +15,7 @@ COMMENT ON FOREIGN TABLE public."FT1_$%{}[]()&*^!@""'`\/#"
IS 'Test Comment';
GRANT ALL ON TABLE public."FT1_$%{}[]()&*^!@""'`\/#" TO enterprisedb;
ALTER TABLE IF EXISTS "FT1_$%{}[]()&*^!@""'`\/#"
ALTER COLUMN col1 SET STATISTICS 10;