似乎无法将此函数设置为Create,即使我清空所有DECLARE块和BEGIN-END块并尝试返回一个字符串。谁能帮我解决我在这里做错了什么?
尝试在pgAdminIII(Ubuntu)中执行此操作:
CREATE OR REPLACE FUNCTION split_country()
RETURNS text as $$
DECLARE
titlecsv text;
arCountries text[];
country_cursor CURSOR
FOR SELECT DISTINCT country
FROM festfriend.films;
BEGIN
OPEN country_cursor;
LOOP
FETCH NEXT FROM country_cursor INTO titlecsv;
EXIT WHEN NOT FOUND;
SELECT regexp_split_to_array(titlecsv, ',') INTO arCountries;
RAISE NOTICE '%1', arCountries;
INSERT INTO festfriend.country (name, acronym)
SELECT trim(both ' ' from a.column2), upper(left(trim(both ' ' from a.column2), 3))
FROM unnest((SELECT arCountries)::text[]) WITH ORDINALITY a(column2)
WHERE (SELECT COUNT(id) FROM festfriend.country WHERE name = trim(both ' ' from a.column2)) = 0
AND char_length(trim(both ' ' from a.column2)) > 0;
END LOOP;
CLOSE country_cursor;
RETURN 'Split Countries, yo!';
END; $$
LANGUAGE 'plpgsql';
收到以下错误:
ERROR: syntax error at or near "CREATE"
LINE 1: CREATE OR REPLACE FUNCTION split_country()
^
********** Error **********
ERROR: syntax error at or near "CREATE"
SQL state: 42601
Character: 1