gpt4 book ai didi

更改函数以便它检索数组类型参数会导致错误 : FUNCTION DOES NOT EXIST

转载 作者:行者123 更新时间:2023-12-01 22:46:10 25 4
gpt4 key购买 nike

我更改了一个函数,使其接收三个参数,而不是仅接收两个。在age--1.2.0.sql文件中,之前设置为:

CREATE FUNCTION ag_catalog.create_vlabel(graph_name name, label_name name)
RETURNS void
LANGUAGE c
AS 'MODULE_PATHNAME';

然后我改为:

CREATE FUNCTION ag_catalog.create_vlabel(graph_name name, label_name name, parent_list name[])
RETURNS void
LANGUAGE c
AS 'MODULE_PATHNAME';

在此之后,我修改了 label_commands.c 文件中的相同函数,以便它检查第三个参数是否为空。如果不是,它遍历列表,将父标签添加到 List *parent,然后创建继承自父标签的标签。这是我添加此功能的代码块:

    // [...]

// Added these variables:

ArrayType *list_parents;
Datum *elements_parent_names;
Name parent_name;
char *parent_name_str;
int num_parents;

// [...]

//Create the default label tables
graph = graph_name->data;
label = label_name->data;

rv = get_label_range_var(graph, graph_oid, AG_DEFAULT_LABEL_VERTEX);
parent = list_make1(rv);

// checking if user has provided the parent's name list.
if (!PG_ARGISNULL(2)) {

// Get the content from the third argument - which is an array.
list_parents = PG_GETARG_ARRAYTYPE_P(2);
num_parents = ArrayGetNItems(ARR_NDIM(list_parents), ARR_DIMS(list_parents));
elements_parent_names = (Datum *) ARR_DATA_PTR(list_parents);

// Check for each parent in the list.
for (int i = 0; i < num_parents; i++) {

parent_name = DatumGetName(elements_parent_names[i]);
parent_name_str = NameStr(*parent_name);

// Check if parent label does not exist
if (!label_exists(parent_name_str, graph_oid)) {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_SCHEMA),
errmsg("parent label \"%s\" does not exist.", parent_name_str)));
}

rv = get_label_range_var(graph, graph_oid, parent_name->data);

lappend(parent, rv);
}
}

create_label(graph, label, LABEL_TYPE_VERTEX, parent);

大家可以查看原码here .

在此之后,我尝试像这样调用函数:

--(this works)

SELECT * FROM ag_catalog.create_vlabel('demo', 'Book');
NOTICE: VLabel "Book" has been created
create_vlabel
---------------

(1 row)

但是如果我这样调用:

--(I get an error)

SELECT * FROM ag_catalog.create_vlabel('demo', 'Fantasy', ARRAY['Book']);
ERROR: function ag_catalog.create_vlabel(unknown, unknown, text[]) does not exist
LINE 1: SELECT * FROM ag_catalog.create_vlabel('demo', 'Fantasy', ARRAY...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

我怎样才能解决这个问题,以便它成功地从传递的数组中获取所有元素?

最佳答案

尝试删除扩展,然后重新创建它。

DROP EXTENSION age CASCADE;
CREATE EXTENSION age;
LOAD age;

关于更改函数以便它检索数组类型参数会导致错误 : FUNCTION DOES NOT EXIST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75404035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com