这个postgreSQL查询有什么问题? [英] What is wrong with this postgreSQL query?

查看:88
本文介绍了这个postgreSQL查询有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PostgreSQL(v8.4)新手,我正在尝试编写一些简单的函数。但是,我的第一个实验已经以惨败告终。我收到错误消息:

I'm a PostgreSQL (v8.4) newbie, and I'm trying to get some simple functions written. My first experiment, however, is already ending in dismal failure. I'm getting the error:

ERROR:  syntax error at or near ";"
LINE 7: begin; 

...我看不到问题所在。根据我一直在审查的文档,这看起来不错。

... and I don't see the problem. This looks right, according to the documentation I've been reviewing.

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;


推荐答案

您应该在开始

这篇关于这个postgreSQL查询有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆