GetFunctionAlterOwnerCommand: use format_procedure_qualified

distributed_functions: test a function with a quote in name
AppendDefElemSet: quote variable names
pull/3227/head
Philip Dubé 2019-11-24 00:29:42 +00:00 committed by Philip Dubé
parent a81e6a81ab
commit 3c10c27b13
4 changed files with 17 additions and 34 deletions

View File

@ -618,29 +618,10 @@ GetFunctionAlterOwnerCommand(const RegProcedure funcOid)
}
/*
* Set search_path to NIL so that all objects outside of pg_catalog will be
* schema-prefixed. pg_catalog will be added automatically when we call
* PushOverrideSearchPath(), since we set addCatalog to true;
*/
OverrideSearchPath *overridePath = GetOverrideSearchPath(CurrentMemoryContext);
overridePath->schemas = NIL;
overridePath->addCatalog = true;
PushOverrideSearchPath(overridePath);
/*
* If the function exists we want to use pg_get_function_identity_arguments to
* If the function exists we want to use format_procedure_qualified to
* serialize its canonical arguments
*/
Datum functionSignatureDatum =
DirectFunctionCall1(regprocedureout, ObjectIdGetDatum(funcOid));
/* revert back to original search_path */
PopOverrideSearchPath();
/* regprocedureout returns cstring */
char *functionSignature = DatumGetCString(functionSignatureDatum);
char *functionSignature = format_procedure_qualified(funcOid);
char *functionOwner = GetUserNameFromId(procOwner, false);
appendStringInfo(alterCommand, "ALTER %s %s OWNER TO %s;",

View File

@ -274,25 +274,27 @@ AppendDefElemSet(StringInfo buf, DefElem *def)
{
case VAR_SET_VALUE:
{
appendStringInfo(buf, " SET %s = %s", setStmt->name, setVariableArgs);
appendStringInfo(buf, " SET %s = %s", quote_identifier(setStmt->name),
setVariableArgs);
break;
}
case VAR_SET_CURRENT:
{
appendStringInfo(buf, " SET %s FROM CURRENT", setStmt->name);
appendStringInfo(buf, " SET %s FROM CURRENT", quote_identifier(
setStmt->name));
break;
}
case VAR_SET_DEFAULT:
{
appendStringInfo(buf, " SET %s TO DEFAULT", setStmt->name);
appendStringInfo(buf, " SET %s TO DEFAULT", quote_identifier(setStmt->name));
break;
}
case VAR_RESET:
{
appendStringInfo(buf, " RESET %s", setStmt->name);
appendStringInfo(buf, " RESET %s", quote_identifier(setStmt->name));
break;
}

View File

@ -70,7 +70,7 @@ CREATE FUNCTION add_without_param_names(integer, integer) RETURNS integer
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
CREATE FUNCTION add_mixed_param_names(integer, val1 integer) RETURNS integer
CREATE FUNCTION "add_mi'xed_param_names"(integer, "va'l1" integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
@ -168,21 +168,21 @@ select bool_or(hasmetadata) from pg_dist_node WHERE isactive AND noderole = 'pr
-- if not paremeters are supplied, we'd see that function doesn't have
-- distribution_argument_index and colocationid
SELECT create_distributed_function('add_mixed_param_names(int, int)');
SELECT create_distributed_function('"add_mi''xed_param_names"(int, int)');
create_distributed_function
-----------------------------
(1 row)
SELECT distribution_argument_index is NULL, colocationid is NULL from citus.pg_dist_object
WHERE objid = 'add_mixed_param_names(int, int)'::regprocedure;
WHERE objid = 'add_mi''xed_param_names(int, int)'::regprocedure;
?column? | ?column?
----------+----------
t | t
(1 row)
-- also show that we can use the function
SELECT * FROM run_command_on_workers('SELECT function_tests.add_mixed_param_names(2,3);') ORDER BY 1,2;
SELECT * FROM run_command_on_workers('SELECT function_tests."add_mi''xed_param_names"(2,3);') ORDER BY 1,2;
nodename | nodeport | success | result
-----------+----------+---------+--------
localhost | 57637 | t | 5
@ -510,7 +510,7 @@ SELECT create_distributed_function('add_with_param_names(int, int)', '$3');
ERROR: cannot distribute the function "add_with_param_names" since the distribution argument is not valid
HINT: Either provide a valid function argument name or a valid "$paramIndex" to create_distributed_function()
SELECT create_distributed_function('add_with_param_names(int, int)', '$1a');
ERROR: invalid input syntax for integer: "1a"
ERROR: invalid input syntax for type integer: "1a"
-- non existing column name
SELECT create_distributed_function('add_with_param_names(int, int)', 'aaa');
ERROR: cannot distribute the function "add_with_param_names" since the distribution argument is not valid

View File

@ -73,7 +73,7 @@ CREATE FUNCTION add_without_param_names(integer, integer) RETURNS integer
IMMUTABLE
RETURNS NULL ON NULL INPUT;
CREATE FUNCTION add_mixed_param_names(integer, val1 integer) RETURNS integer
CREATE FUNCTION "add_mi'xed_param_names"(integer, "va'l1" integer) RETURNS integer
AS 'select $1 + $2;'
LANGUAGE SQL
IMMUTABLE
@ -170,12 +170,12 @@ select bool_or(hasmetadata) from pg_dist_node WHERE isactive AND noderole = 'pr
-- if not paremeters are supplied, we'd see that function doesn't have
-- distribution_argument_index and colocationid
SELECT create_distributed_function('add_mixed_param_names(int, int)');
SELECT create_distributed_function('"add_mi''xed_param_names"(int, int)');
SELECT distribution_argument_index is NULL, colocationid is NULL from citus.pg_dist_object
WHERE objid = 'add_mixed_param_names(int, int)'::regprocedure;
WHERE objid = 'add_mi''xed_param_names(int, int)'::regprocedure;
-- also show that we can use the function
SELECT * FROM run_command_on_workers('SELECT function_tests.add_mixed_param_names(2,3);') ORDER BY 1,2;
SELECT * FROM run_command_on_workers('SELECT function_tests."add_mi''xed_param_names"(2,3);') ORDER BY 1,2;
-- make sure that none of the active and primary nodes hasmetadata
-- since the function doesn't have a parameter