[pgAdmin][RM4451]Cannot construct SQL script for composite type having only one field variable
Aditya Toshniwal <[email protected]>
| Newsgroups | gmane.comp.db.postgresql.pgadmin.devel |
|---|---|
| Message-ID | <CAM9w-_kU7FWKee=BB7wZYnN5cNt0AQ=bZX-0jS3BdMs8rpUPjw@mail.gmail.com> |
Hi Hackers, pgAdmin allows to create composite type only with 2 or more members. Attached is the patch to remove the restriction as PostgreSQL allows zero or more and fix the issue where SQL is not generated for types having less than 2 members. Kindly review. -- Thanks and Regards, Aditya Toshniwal Sr. Software Engineer | EnterpriseDB India | Pune "Don't Complain about Heat, Plant a TREE"
RM4451.patch
(application/octet-stream, 3.7 KB)
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
index 8d428dc1f..b50e6d7d7 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/__init__.py
@@ -929,16 +929,6 @@ class TypeView(PGChildNodeView, DataTypeReader):
)
)
# Additional checks goes here
- # If type is composite then check if it has two members
- if data and data[arg] == 'c':
- if len(data['composite']) < 2:
- return make_json_response(
- status=410,
- success=0,
- errormsg=gettext(
- 'Composite types require at least two members.'
- )
- )
# If type is range then check if subtype is defined or not
if data and data[arg] == 'r':
if 'typname' not in data or data['typname'] is None:
@@ -1285,11 +1275,6 @@ class TypeView(PGChildNodeView, DataTypeReader):
return "-- definition incomplete"
# Additional checks go here
- # If type is composite then check if it has two members
- if data and data[arg] == 'c':
- if len(data['composite']) < 2:
- return "-- definition incomplete"
-
# If type is range then check if subtype is defined or not
if data and data[arg] == 'r':
if 'typname' not in data or data['typname'] is None:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_composite_type_one_field.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_composite_type_one_field.sql
new file mode 100644
index 000000000..16d5758bb
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/create_composite_type_one_field.sql
@@ -0,0 +1,11 @@
+-- Type: composite_type_$%{}[]()&*^!@"'`\/#
+
+-- DROP TYPE public."composite_type_$%{}[]()&*^!@""'`\/#";
+
+CREATE TYPE public."composite_type_$%{}[]()&*^!@""'`\/#" AS
+(
+ mname1 bigint
+);
+
+ALTER TYPE public."composite_type_$%{}[]()&*^!@""'`\/#"
+ OWNER TO <OWNER>;
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/tests.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/tests.json
index caded7697..60a17b5a7 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/tests.json
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/types/tests/default/tests.json
@@ -108,6 +108,32 @@
"data": {}
},
+ {
+ "type": "create",
+ "name": "Create Composite type - one field",
+ "endpoint": "NODE-type.obj",
+ "sql_endpoint": "NODE-type.sql_id",
+ "data": {
+ "name": "composite_type_$%{}[]()&*^!@\"'`\\/#",
+ "is_sys_type":false,
+ "typtype":"c",
+ "schema":"public",
+ "composite":[
+ {"member_name":"mname1","type":"bigint","is_tlength":false,"is_precision":false}
+ ],
+ "typacl":[],
+ "seclabels":[],
+ "description":""
+ },
+ "expected_sql_file": "create_composite_type_one_field.sql"
+ },
+ {
+ "type": "delete",
+ "name": "Drop Composite type - one field",
+ "endpoint": "NODE-type.obj_id",
+ "sql_endpoint": "NODE-type.sql_id",
+ "data": {}
+ },
{
"type": "create",