public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][Patch]: RM #4362 trigger function create script
5+ messages / 2 participants
[nested] [flat]

* [pgAdmin4][Patch]: RM #4362 trigger function create script
@ 2019-06-19 08:55  Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Akshay Joshi @ 2019-06-19 08:55 UTC (permalink / raw)
  To: pgadmin-hackers

Hi Hackers,

Attached is the patch to fix RM #4362 trigger function create script.
Please review it.

-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


Attachments:

  [application/octet-stream] RM_4362.patch (7.6K, 3-RM_4362.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/11_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/11_plus/create.sql
index b3836456..bcfc8f36 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/11_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/11_plus/create.sql
@@ -4,7 +4,8 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.proargnames %}{{data.proargnames}}{% endif %})
-    RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
+    RETURNS{% if data.proretset and data.prorettypename.startswith('SETOF ') %} {{ data.prorettypename }} {% elif data.proretset %} SETOF {{ data.prorettypename }}{% else %} {{ data.prorettypename }}{% endif %}
+
     LANGUAGE {{ data.lanname|qtLiteral }}
 {% if data.procost %}
     COST {{data.procost}}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/9.2_plus/create.sql
index ea06fd04..af87cfe9 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/9.2_plus/create.sql
@@ -4,7 +4,8 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}()
-    RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
+    RETURNS{% if data.proretset and data.prorettypename.startswith('SETOF ') %} {{ data.prorettypename }} {% elif data.proretset %} SETOF {{ data.prorettypename }}{% else %} {{ data.prorettypename }}{% endif %}
+
     LANGUAGE {{ data.lanname|qtLiteral }}
 {% if data.procost %}
     COST {{data.procost}}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/9.5_plus/create.sql
index b3836456..bcfc8f36 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/9.5_plus/create.sql
@@ -4,7 +4,8 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}({% if data.proargnames %}{{data.proargnames}}{% endif %})
-    RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
+    RETURNS{% if data.proretset and data.prorettypename.startswith('SETOF ') %} {{ data.prorettypename }} {% elif data.proretset %} SETOF {{ data.prorettypename }}{% else %} {{ data.prorettypename }}{% endif %}
+
     LANGUAGE {{ data.lanname|qtLiteral }}
 {% if data.procost %}
     COST {{data.procost}}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/default/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/default/create.sql
index d2b6d12b..e3d0cc20 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/default/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/pg/sql/default/create.sql
@@ -4,7 +4,8 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}()
-    RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
+    RETURNS{% if data.proretset and data.prorettypename.startswith('SETOF ') %} {{ data.prorettypename }} {% elif data.proretset %} SETOF {{ data.prorettypename }}{% else %} {{ data.prorettypename }}{% endif %}
+
     LANGUAGE {{ data.lanname|qtLiteral }}
 {% if data.procost %}
     COST {{data.procost}}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/9.2_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/9.2_plus/create.sql
index c59ecea6..3c850616 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/9.2_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/9.2_plus/create.sql
@@ -4,7 +4,8 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}()
-    RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
+    RETURNS{% if data.proretset and data.prorettypename.startswith('SETOF ') %} {{ data.prorettypename }} {% elif data.proretset %} SETOF {{ data.prorettypename }}{% else %} {{ data.prorettypename }}{% endif %}
+
     LANGUAGE {{ data.lanname|qtLiteral }}
 {% if data.procost %}
     COST {{data.procost}}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/9.5_plus/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/9.5_plus/create.sql
index 64f1b761..a679f740 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/9.5_plus/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/9.5_plus/create.sql
@@ -4,7 +4,8 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}()
-    RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
+    RETURNS{% if data.proretset and data.prorettypename.startswith('SETOF ') %} {{ data.prorettypename }} {% elif data.proretset %} SETOF {{ data.prorettypename }}{% else %} {{ data.prorettypename }}{% endif %}
+
     LANGUAGE {{ data.lanname|qtLiteral }}
 {% if data.procost %}
     COST {{data.procost}}
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/default/create.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/default/create.sql
index d2b6d12b..e3d0cc20 100644
--- a/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/default/create.sql
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/functions/templates/trigger_functions/ppas/sql/default/create.sql
@@ -4,7 +4,8 @@
 {% set is_columns = [] %}
 {% if data %}
 CREATE FUNCTION {{ conn|qtIdent(data.pronamespace, data.name) }}()
-    RETURNS{% if data.proretset %} SETOF{% endif %} {{ conn|qtTypeIdent(data.prorettypename) }}
+    RETURNS{% if data.proretset and data.prorettypename.startswith('SETOF ') %} {{ data.prorettypename }} {% elif data.proretset %} SETOF {{ data.prorettypename }}{% else %} {{ data.prorettypename }}{% endif %}
+
     LANGUAGE {{ data.lanname|qtLiteral }}
 {% if data.procost %}
     COST {{data.procost}}


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

* Re: [pgAdmin4][Patch]: RM #4362 trigger function create script
@ 2019-06-19 14:27  Dave Page <[email protected]>
  parent: Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Dave Page @ 2019-06-19 14:27 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Hi

On Wed, Jun 19, 2019 at 9:55 AM Akshay Joshi <[email protected]>
wrote:

> Hi Hackers,
>
> Attached is the patch to fix RM #4362 trigger function create script.
> Please review it.
>

While I can see how this works, I question why we have the string "SETOF"
in prorettypname anyway? That's a separate property, so it should be in a
separate variable. What if I have a type called "SETOFDavesStuff"
(unlikely, but it illustrates the point)?

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

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


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

* Re: [pgAdmin4][Patch]: RM #4362 trigger function create script
@ 2019-06-19 15:17  Akshay Joshi <[email protected]>
  parent: Dave Page <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Akshay Joshi @ 2019-06-19 15:17 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi Dave

On Wed, 19 Jun, 2019, 19:57 Dave Page, <[email protected]> wrote:

> Hi
>
> On Wed, Jun 19, 2019 at 9:55 AM Akshay Joshi <
> [email protected]> wrote:
>
>> Hi Hackers,
>>
>> Attached is the patch to fix RM #4362 trigger function create script.
>> Please review it.
>>
>
> While I can see how this works, I question why we have the string "SETOF"
> in prorettypname anyway? That's a separate property, so it should be in a
> separate variable. What if I have a type called "SETOFDavesStuff"
> (unlikely, but it illustrates the point)?
>

    We have used pg_get_function_result(func_oid) to get the returns clause
for function and assign its value to prorettypename variable. I have
followed the same logic for trigger function and fixed it. Similar logic
has already been used for functions.

>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


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

* Re: [pgAdmin4][Patch]: RM #4362 trigger function create script
@ 2019-06-20 06:48  Akshay Joshi <[email protected]>
  parent: Akshay Joshi <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Akshay Joshi @ 2019-06-20 06:48 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

Hi Dave

On Wed, Jun 19, 2019 at 8:47 PM Akshay Joshi <[email protected]>
wrote:

> Hi Dave
>
> On Wed, 19 Jun, 2019, 19:57 Dave Page, <[email protected]> wrote:
>
>> Hi
>>
>> On Wed, Jun 19, 2019 at 9:55 AM Akshay Joshi <
>> [email protected]> wrote:
>>
>>> Hi Hackers,
>>>
>>> Attached is the patch to fix RM #4362 trigger function create script.
>>> Please review it.
>>>
>>
>> While I can see how this works, I question why we have the string "SETOF"
>> in prorettypname anyway? That's a separate property, so it should be in a
>> separate variable. What if I have a type called "SETOFDavesStuff"
>> (unlikely, but it illustrates the point)?
>>
>
>     We have used pg_get_function_result(func_oid) to get the returns
> clause for function and assign its value to prorettypename variable. I have
> followed the same logic for trigger function and fixed it. Similar logic
> has already been used for functions.
>

    I have tested it with two different type "SETOF TypeTest" and
"SETOFType" for function, as trigger_function only have return type either
trigger or event_trigger. I haven't found any issue with the reverse
engineered sql and create script as well.

>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>

-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


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

* Re: [pgAdmin4][Patch]: RM #4362 trigger function create script
@ 2019-06-20 12:19  Dave Page <[email protected]>
  parent: Akshay Joshi <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Dave Page @ 2019-06-20 12:19 UTC (permalink / raw)
  To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers

Thanks, applied.

On Thu, Jun 20, 2019 at 7:48 AM Akshay Joshi <[email protected]>
wrote:

> Hi Dave
>
> On Wed, Jun 19, 2019 at 8:47 PM Akshay Joshi <
> [email protected]> wrote:
>
>> Hi Dave
>>
>> On Wed, 19 Jun, 2019, 19:57 Dave Page, <[email protected]> wrote:
>>
>>> Hi
>>>
>>> On Wed, Jun 19, 2019 at 9:55 AM Akshay Joshi <
>>> [email protected]> wrote:
>>>
>>>> Hi Hackers,
>>>>
>>>> Attached is the patch to fix RM #4362 trigger function create script.
>>>> Please review it.
>>>>
>>>
>>> While I can see how this works, I question why we have the string
>>> "SETOF" in prorettypname anyway? That's a separate property, so it should
>>> be in a separate variable. What if I have a type called "SETOFDavesStuff"
>>> (unlikely, but it illustrates the point)?
>>>
>>
>>     We have used pg_get_function_result(func_oid) to get the returns
>> clause for function and assign its value to prorettypename variable. I have
>> followed the same logic for trigger function and fixed it. Similar logic
>> has already been used for functions.
>>
>
>     I have tested it with two different type "SETOF TypeTest" and
> "SETOFType" for function, as trigger_function only have return type either
> trigger or event_trigger. I haven't found any issue with the reverse
> engineered sql and create script as well.
>
>>
>>> --
>>> Dave Page
>>> Blog: http://pgsnake.blogspot.com
>>> Twitter: @pgsnake
>>>
>>> EnterpriseDB UK: http://www.enterprisedb.com
>>> The Enterprise PostgreSQL Company
>>>
>>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
>
> *Sr. Software Architect*
> *EnterpriseDB Software India Private Limited*
> *Mobile: +91 976-788-8246*
>


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

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


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


end of thread, other threads:[~2019-06-20 12:19 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-06-19 08:55 [pgAdmin4][Patch]: RM #4362 trigger function create script Akshay Joshi <[email protected]>
2019-06-19 14:27 ` Dave Page <[email protected]>
2019-06-19 15:17   ` Akshay Joshi <[email protected]>
2019-06-20 06:48     ` Akshay Joshi <[email protected]>
2019-06-20 12:19       ` 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