public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin][RM4451]Cannot construct SQL script for composite type having only one field variable
2+ messages / 2 participants
[nested] [flat]

* [pgAdmin][RM4451]Cannot construct SQL script for composite type having only one field variable
@ 2019-11-01 09:53  Aditya Toshniwal <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Aditya Toshniwal @ 2019-11-01 09:53 UTC (permalink / raw)
  To: pgadmin-hackers

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",


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [pgAdmin][RM4451]Cannot construct SQL script for composite type having only one field variable
@ 2019-11-01 15:22  Dave Page <[email protected]>
  parent: Aditya Toshniwal <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Dave Page @ 2019-11-01 15:22 UTC (permalink / raw)
  To: Aditya Toshniwal <[email protected]>; +Cc: pgadmin-hackers

Thanks, patch applied.

On Fri, Nov 1, 2019 at 9:54 AM Aditya Toshniwal <
[email protected]> wrote:

> 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"
>


-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2019-11-01 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-01 09:53 [pgAdmin][RM4451]Cannot construct SQL script for composite type having only one field variable Aditya Toshniwal <[email protected]>
2019-11-01 15:22 ` Dave Page <[email protected]>

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