From 101e2cb410019565000a0436d8cfa770c50a6858 Mon Sep 17 00:00:00 2001 From: yogeshmahajan-1903 Date: Thu, 25 Jan 2024 16:27:19 +0530 Subject: [PATCH] Ensure correct sql is generated while changing column data type to char.#7113 --- .../templates/foreign_table_columns/sql/default/update.sql | 4 ++-- .../foreign_tables/tests/foreign_tables_test_data.json | 2 +- .../schemas/tables/templates/columns/sql/14_plus/update.sql | 4 ++-- .../schemas/tables/templates/columns/sql/default/update.sql | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_table_columns/sql/default/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_table_columns/sql/default/update.sql index 38413c3996e..36f6c6915a7 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_table_columns/sql/default/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/templates/foreign_table_columns/sql/default/update.sql @@ -35,8 +35,8 @@ ALTER FOREIGN TABLE IF EXISTS {{conn|qtIdent(data.schema, data.table)}} -- the current datatype cannot be cast to the target cltype so this conversion cannot be made automatically. {% endif %} {% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %}ALTER FOREIGN TABLE IF EXISTS {{conn|qtIdent(data.schema, data.table)}} -{% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %} ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname != o_data.collspcname %} - COLLATE {{data.collspcname}}{% elif o_data.collspcname %} COLLATE {{o_data.collspcname}}{% endif %}; +{% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %} ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname is not none %}{%if data.collspcname != o_data.collspcname %} + COLLATE {{data.collspcname}}{% elif data.collspcname is not none and o_data.collspcname %} COLLATE {{o_data.collspcname}}{% endif %}{% endif %}; {% endif %} {### Alter column default value ###} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/foreign_tables_test_data.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/foreign_tables_test_data.json index 82f1f0ca529..3e2db677197 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/foreign_tables_test_data.json +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/tests/foreign_tables_test_data.json @@ -269,7 +269,7 @@ } ], "name": "emp", - "cltype": "text", + "cltype": "\"char\"", "attlen": null, "attnum": 1, "attnotnull": false, diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/14_plus/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/14_plus/update.sql index ecccc7db72c..fa8a6f54b99 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/14_plus/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/14_plus/update.sql @@ -17,8 +17,8 @@ ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.table)}} {% endif %} {% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %}ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} -{% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %} ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname != o_data.collspcname %} - COLLATE {{data.collspcname}}{% elif o_data.collspcname %} COLLATE {{o_data.collspcname}}{% endif %}; +{% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %} ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname is not none and data.collspcname != o_data.collspcname %} + COLLATE {{data.collspcname}}{% elif data.collspcname is not none and o_data.collspcname %} COLLATE {{o_data.collspcname}}{% endif %}; {% endif %} {### Alter column default value ###} {% if is_view_only and data.defval is defined and data.defval is not none and data.defval != '' and data.defval != o_data.defval %} diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/update.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/update.sql index 6da49a9c818..a52f4ca061c 100644 --- a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/update.sql +++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/columns/sql/default/update.sql @@ -17,8 +17,8 @@ ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.table)}} {% endif %} {% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %}ALTER TABLE {{conn|qtIdent(data.schema, data.table)}} -{% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %} ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname != o_data.collspcname %} - COLLATE {{data.collspcname}}{% elif o_data.collspcname %} COLLATE {{o_data.collspcname}}{% endif %}; +{% if data.col_type_conversion is defined and data.col_type_conversion == False %} -- {% endif %} ALTER COLUMN {% if data.name %}{{conn|qtTypeIdent(data.name)}}{% else %}{{conn|qtTypeIdent(o_data.name)}}{% endif %} TYPE {{ GET_TYPE.UPDATE_TYPE_SQL(conn, data, o_data) }}{% if data.collspcname and data.collspcname is not none %}{%if data.collspcname != o_data.collspcname %} + COLLATE {{data.collspcname}}{% elif data.collspcname is not none and o_data.collspcname %} COLLATE {{o_data.collspcname}}{% endif %}{% endif %}; {% endif %} {### Alter column default value ###} {% if is_view_only and data.defval is defined and data.defval is not none and data.defval != '' and data.defval != o_data.defval %}