Version: postgreSQL 9.3
我已经写了以下程序:
CREATE OR REPLACE FUNCTION drop_if_exists(table_name name, schema_name name) RETURNS integer AS $$
BEGIN
IF(SELECT EXISTS(
SELECT *
FROM pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE relname = table_name AND
nspname = schema_name
) as ex) = true
THEN
execute 'DROP TABLE ' || schema_name || '.' || table_name;
RETURN 1;
ELSE
RETURN 0;
END IF;
END
$$ LANGUAGE plpgsql;
DO $$
BEGIN
drop_if_exists('ords', 'public'); --ERROR: syntax error at or near drop_if_exists"
END
$$ LANGUAGE plpgsql;
该代码存在哪些问题?
答案 0 :(得分:1)
缺少perform
就是一个。没有检查其他错误。
perform drop_if_exists(...