我是PostgreSQL(v8.4)的新手,我正在尝试编写一些简单的函数。然而,我的第一个实验已经以惨淡的失败告终。我收到了错误:
ERROR: syntax error at or near ";"
LINE 7: begin;
......我没有看到问题。根据我一直在审查的文件,这看起来是正确的。
create or replace function create_user(
user_name varchar(250),
email_address varchar(250),
approved boolean,
email_is_unique boolean
) returns boolean as $$
begin;
if email_is_unique
&& exists(select null from users as u where u.email = email_address) then
raise exception 'The email address specified is already in use, and email addresses are configured to be unique.';
end if;
insert into users
(
user_name,
email
)
values
(
user_name,
email_address
);
return true;
end;
$$ language plpgsql;
答案 0 :(得分:2)
您应该在begin