public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin][RM4451]Cannot construct SQL script for composite type having only one field variable
Date: Fri, 1 Nov 2019 15:23:29 +0530
Message-ID: <CAM9w-_kU7FWKee=BB7wZYnN5cNt0AQ=bZX-0jS3BdMs8rpUPjw@mail.gmail.com> (raw)

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"


Attachments:

  [application/octet-stream] RM4451.patch (3.7K, 3-RM4451.patch)
  download | inline diff:
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",


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin][RM4451]Cannot construct SQL script for composite type having only one field variable
  In-Reply-To: <CAM9w-_kU7FWKee=BB7wZYnN5cNt0AQ=bZX-0jS3BdMs8rpUPjw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox