Amazon Redshift CREATE FUNCTION ERROR: 42601: syntax error at or near "default"
Amazon Redshift CREATE FUNCTION ERROR: 42601: syntax error at or near "default"
我试图通过 Aginity (v4.9.1.2686) 在 Redshift 中创建一个函数,但出现以下错误:
ERROR: 42601: syntax error at or near "default"
函数代码:
CREATE OR REPLACE FUNCTION search_columns (
searchfield text,
searchtables name[] default '{}',
searchschema name[] default '{}')
RETURNS table(schemaname text, tablename text, columnname text, rowctid text)
AS $$
begin
FOR schemaname, tablename, columnname IN
SELECT c.table_schema, c.table_name, c.column_name
FROM information_schema.columns c
JOIN information_schema.tables t ON (t.table_name = c.table_name AND t.table_schema = c.table_schema)
WHERE (c.table_name=ANY(searchtables) OR searchtables='{}')
AND (c.table_schema=ANY(searchschema) OR searchschema='{}')
AND t.table_type='BASE TABLE'
LOOP
EXECUTE format('SELECT ctid FROM %I.%I WHERE cast(%I as text)=%L', schemaname, tablename, columnname, searchfield)
INTO rowctid;
IF rowctid IS NOT NULL
THEN RETURN NEXT;
END IF;
END LOOP;
END;
$$ language plpgsql;
编辑
尝试删除默认值并出现不同的错误:
ERROR: 42601: syntax error at or near "table"
CREATE OR REPLACE FUNCTION search_columns (
searchfield text,
searchtables name[] ,
searchschema name[] )
RETURNS table(schemaname text, tablename text, columnname text, rowctid text)
AS $$
begin
FOR schemaname, tablename, columnname IN
SELECT c.table_schema, c.table_name, c.column_name
FROM information_schema.columns c
JOIN information_schema.tables t ON (t.table_name = c.table_name AND t.table_schema = c.table_schema)
WHERE (c.table_name=ANY(searchtables) OR searchtables='{}')
AND (c.table_schema=ANY(searchschema) OR searchschema='{}')
AND t.table_type = 'BASE TABLE'
LOOP
EXECUTE format('SELECT ctid FROM %I.%I WHERE cast(%I as text)=%L', schemaname, tablename, columnname, searchfield)
INTO rowctid;
IF rowctid IS NOT NULL
THEN RETURN NEXT;
END IF;
END LOOP;
END;
$$ language plpgsql;
我试图通过 Aginity (v4.9.1.2686) 在 Redshift 中创建一个函数,但出现以下错误:
ERROR: 42601: syntax error at or near "default"
函数代码:
CREATE OR REPLACE FUNCTION search_columns (
searchfield text,
searchtables name[] default '{}',
searchschema name[] default '{}')
RETURNS table(schemaname text, tablename text, columnname text, rowctid text)
AS $$
begin
FOR schemaname, tablename, columnname IN
SELECT c.table_schema, c.table_name, c.column_name
FROM information_schema.columns c
JOIN information_schema.tables t ON (t.table_name = c.table_name AND t.table_schema = c.table_schema)
WHERE (c.table_name=ANY(searchtables) OR searchtables='{}')
AND (c.table_schema=ANY(searchschema) OR searchschema='{}')
AND t.table_type='BASE TABLE'
LOOP
EXECUTE format('SELECT ctid FROM %I.%I WHERE cast(%I as text)=%L', schemaname, tablename, columnname, searchfield)
INTO rowctid;
IF rowctid IS NOT NULL
THEN RETURN NEXT;
END IF;
END LOOP;
END;
$$ language plpgsql;
编辑
尝试删除默认值并出现不同的错误:
ERROR: 42601: syntax error at or near "table"
CREATE OR REPLACE FUNCTION search_columns (
searchfield text,
searchtables name[] ,
searchschema name[] )
RETURNS table(schemaname text, tablename text, columnname text, rowctid text)
AS $$
begin
FOR schemaname, tablename, columnname IN
SELECT c.table_schema, c.table_name, c.column_name
FROM information_schema.columns c
JOIN information_schema.tables t ON (t.table_name = c.table_name AND t.table_schema = c.table_schema)
WHERE (c.table_name=ANY(searchtables) OR searchtables='{}')
AND (c.table_schema=ANY(searchschema) OR searchschema='{}')
AND t.table_type = 'BASE TABLE'
LOOP
EXECUTE format('SELECT ctid FROM %I.%I WHERE cast(%I as text)=%L', schemaname, tablename, columnname, searchfield)
INTO rowctid;
IF rowctid IS NOT NULL
THEN RETURN NEXT;
END IF;
END LOOP;
END;
$$ language plpgsql;