Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues reported while testing foreign table properties.#640. #6845

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,8 @@ def _check_for_column_delete(self, columns, data, column_sql):
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]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'%}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) }}(
Expand All @@ -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 %}
Expand Down Expand Up @@ -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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading