- Add support for creating a function with custom return type. #6854

- Fixed an issue where create object dialog title was not showing object type name.
This commit is contained in:
Pravesh Sharma 2023-11-28 15:54:44 +05:30 committed by GitHub
parent 3bd2dec663
commit 412375af3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 473 additions and 6 deletions

View File

@ -35,8 +35,10 @@ Click the *Definition* tab to continue.
Use the fields in the *Definition* tab to define the function:
* Move the *Custom return type?* switch to provide a user defined return type.
* Use the drop-down listbox next to *Return type* to select the data type
returned by the function, if any.
returned by the function, if any. If *Custom return type?* is enabled this field
will change to an input text field.
* Use the drop-down listbox next to *Language* to select the implementation
language. The default is *sql*.
* Use the fields in the *Arguments* to define an argument. Click the *Add*

Binary file not shown.

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 88 KiB

View File

@ -762,7 +762,7 @@ class FunctionView(PGChildNodeView, DataTypeReader, SchemaDiffObjectCompare):
fnid: Function Id
"""
res = [{'label': '', 'value': ''}]
res = []
try:
sql = render_template("/".join([self.sql_template_path,
'get_languages.sql'])

View File

@ -125,6 +125,7 @@ export default class FunctionSchema extends BaseUISchema {
acl: [],
sysfunc: undefined,
sysproc: undefined,
customreturn: false,
...initValues
});
@ -244,12 +245,33 @@ export default class FunctionSchema extends BaseUISchema {
},{
id: 'proargtypenames', label: gettext('Signature arguments'), cell:
'string', type: 'text', group: gettext('Definition'), mode: ['properties'],
},{
id: 'customreturn', label: gettext('Custom return type?'), type: 'switch',
mode: ['create'], group: gettext('Definition'), readonly: obj.isReadonly,
visible: obj.isVisible,
},{
id: 'prorettypename', label: gettext('Return type'), cell: 'string',
type: 'select', group: gettext('Definition'),
options: this.fieldOptions.getTypes,
type: state => {
if(state.customreturn) {
return {
type: 'text',
};
} else {
return {
type: 'select',
options: this.fieldOptions.getTypes,
};
}
}, group: gettext('Definition'), deps:['customreturn'],
readonly: obj.isReadonly, first_empty: true,
mode: ['create'], visible: obj.isVisible,
depChange: (state, source) => {
if(source[0] === 'customreturn') {
return {
prorettypename: undefined
};
}
},
},{
id: 'prorettypename', label: gettext('Return type'), cell: 'string',
type: 'text', group: gettext('Definition'),

View File

@ -300,6 +300,53 @@
"expected_sql_file": "alter_function_delete_acl.sql",
"expected_msql_file": "alter_function_delete_acl.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",

View File

@ -300,6 +300,53 @@
"expected_sql_file": "alter_function_delete_acl.sql",
"expected_msql_file": "alter_function_delete_acl.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",

View File

@ -340,6 +340,53 @@
"expected_sql_file": "create_atomic_func.sql",
"expected_msql_file": "create_atomic_func.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",

View File

@ -0,0 +1,13 @@
CREATE FUNCTION public."Function3_$%{}[]()&*^!@""'`\/#"(IN param character varying DEFAULT '1')
RETURNS table(val character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
AS $BODY$
begin
return query select '1'::character varying;
end
$BODY$;
ALTER FUNCTION public."Function3_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO postgres;

View File

@ -0,0 +1,21 @@
-- FUNCTION: public.Function3_$%{}[]()&*^!@"'`\/#(character varying)
-- DROP FUNCTION IF EXISTS public."Function3_$%{}[]()&*^!@""'`\/#"(character varying);
CREATE OR REPLACE FUNCTION public."Function3_$%{}[]()&*^!@""'`\/#"(
param character varying DEFAULT '1'::character varying)
RETURNS TABLE(val character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query select '1'::character varying;
end
$BODY$;
ALTER FUNCTION public."Function3_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO postgres;

View File

@ -300,6 +300,53 @@
"expected_sql_file": "alter_function_delete_acl.sql",
"expected_msql_file": "alter_function_delete_acl.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "postgres",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",

View File

@ -312,6 +312,53 @@
"expected_sql_file": "alter_function_delete_acl.sql",
"expected_msql_file": "alter_function_delete_acl.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",

View File

@ -312,6 +312,53 @@
"expected_sql_file": "alter_function_delete_acl.sql",
"expected_msql_file": "alter_function_delete_acl.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",

View File

@ -352,6 +352,53 @@
"expected_sql_file": "create_atomic_func.sql",
"expected_msql_file": "create_atomic_func.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",

View File

@ -0,0 +1,13 @@
CREATE FUNCTION public."Function3_$%{}[]()&*^!@""'`\/#"(IN param character varying DEFAULT '1')
RETURNS table(val character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
AS $BODY$
begin
return query select '1'::character varying;
end
$BODY$;
ALTER FUNCTION public."Function3_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO enterprisedb;

View File

@ -0,0 +1,21 @@
-- FUNCTION: public.Function3_$%{}[]()&*^!@"'`\/#(character varying)
-- DROP FUNCTION IF EXISTS public."Function3_$%{}[]()&*^!@""'`\/#"(character varying);
CREATE OR REPLACE FUNCTION public."Function3_$%{}[]()&*^!@""'`\/#"(
param character varying DEFAULT '1'::character varying)
RETURNS TABLE(val character varying)
LANGUAGE 'plpgsql'
COST 100
VOLATILE LEAKPROOF STRICT SECURITY DEFINER WINDOW PARALLEL UNSAFE
ROWS 1000
AS $BODY$
begin
return query select '1'::character varying;
end
$BODY$;
ALTER FUNCTION public."Function3_$%{}[]()&*^!@""'`\/#"(character varying)
OWNER TO enterprisedb;

View File

@ -312,6 +312,53 @@
"expected_sql_file": "alter_function_delete_acl.sql",
"expected_msql_file": "alter_function_delete_acl.msql"
},
{
"type": "delete",
"name": "Drop function",
"endpoint": "NODE-function.delete_id",
"data": {
}
},
{
"type": "create",
"endpoint": "NODE-function.obj",
"msql_endpoint": "NODE-function.msql",
"sql_endpoint": "NODE-function.sql_id",
"name": "Create function with custom return type.",
"data": {
"name": "Function3_$%{}[]()&*^!@\"'`\\/#",
"funcowner": "enterprisedb",
"pronamespace": 2200,
"prorettypename": "table(val character varying)",
"lanname": "plpgsql",
"provolatile": "v",
"proretset": false,
"proisstrict": true,
"prosecdef": true,
"proiswindow": true,
"proparallel": "u",
"procost": "100",
"prorows": "0",
"proleakproof": true,
"arguments": [
{
"argtype": "character varying",
"argmode": "IN",
"argname": "param",
"argdefval": "'1'"
}
],
"prosrc": "begin\n return query select '1'::character varying;\nend",
"probin": "$libdir/",
"options": [],
"variables": [],
"seclabels": [],
"acl": [],
"schema": "public"
},
"expected_sql_file": "create_function_with_custom_return.sql",
"expected_msql_file": "create_function_with_custom_return.msql"
},
{
"type": "delete",
"name": "Drop function",

View File

@ -90,7 +90,7 @@ define('pgadmin.browser.node', [
title: function(d, action) {
if(action == 'create') {
return gettext('Create - %s', this._label);
return gettext('Create - %s', this.label);
}
return d._label??'';
},

View File

@ -85,7 +85,6 @@ const styles = ((theme)=>({
width: '100%',
height: '100%',
color: theme.palette.text.primary,
fontFamily: 'sans-serif',
backgroundColor: theme.otherVars.erdCanvasBg,
backgroundImage: getCanvasGrid(theme),
cursor: 'unset',