user610217
user610217

Reputation:

What is wrong with this postgreSQL query?

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;

Upvotes: 0

Views: 918

Answers (1)

Mansuro
Mansuro

Reputation: 4617

You should remove the semicolon after begin

Upvotes: 2

Related Questions