I have created a vertex
student:
test=# SELECT * FROM cypher('graph', $$
CREATE (s:student{name:"Muneeb", courses: ["OOP", "DS", "Programming", "Android"]})
RETURN s
$$) as (student agtype);
----------------------------------------------------------------------------------------
student
----------------------------------------------------------------------------------------
{"id": 3377699720527873, "label": "student", "properties": {"name": "Muneeb", "courses": ["OOP", "DS", "Programming", "Android"]}}::vertex
(1 row)
It contains courses in its property, which has list of courses in it.
I have created a function that should return 2nd index of the List, in PG_Catalog
.
test=# CREATE OR REPLACE FUNCTION pg_catalog.second_in_list(list agtype)
RETURNS agtype AS $$
BEGIN
return list[1];
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION
When I call this function:
test=# SELECT * FROM cypher('graph', $$
Match (s:student) Return pg_catalog.second_in_list(s.courses)
$$) as (student agtype);
I am getting this error:
ERROR: cannot subscript type agtype because it is not an array
CONTEXT: SQL statement "SELECT list[1]"
PL/pgSQL function second_in_list(agtype) line 3 at RETURN
I have tried passing list agtype[]
as argument to pg_catalog
function but it also not work.