Есть таблица | Код | create table admins ( id integer default nextval ('user_seq') primary key, creation_moment timestamp not null default 'now()', login t_login not null, password varchar(72) not null, display_name varchar(255) not null, description text null, is_deleted boolean not null default false, suspend_reason text null -- if not null then is suspended with reason else not suspended );
|
есть функция проверяющая логин (он не должен повторяться) | Код | --checkes login violation and checkes if login as deleted create or replace function sp_check_login (p_login varchar) returns boolean as $$ declare v_login varchar; v_violation boolean; begin v_login := p_login; loop --checking table admins if exists (select login from admins where admins.login = v_login and not is_deleted) then v_violation := true; if v_violation = true then raise exception 'login % already exists in table admins', v_login ; exit; end if; end if; --checking table customers if exists (select login from customers where customers.login = v_login and not is_deleted) then v_violation = true; if v_violation = true then raise exception 'login % already exists in table customers', v_login; exit; end if; end if; --checking table owners if exists (select login from owners where owners.login = v_login and not is_deleted) then v_violation = true; if v_violation = true then raise exception 'login % already exists in table owners', v_login; exit; end if; end if; return v_violation; end loop; end; $$language plpgsql;
|
теперь вопрос как написать функцию которая заполняла бы таблицу admins ? Я пробую так | Код | create or replace function sp_create_admin (user_seq, timestamp, varchar, varchar, text, text, boolean, text) returns integer as $$ declare begin if (select sp_check_login ($3)) = false then insert into admins (id, creation_moment, login, password, display_name, description, is_deleted, suspend_reason) values ($1, $2, $3, $4, $5, $6, $7, $8); end if; end; $$language plpgsql;
|
но при введении значений, к примеру : | Код | select sp_create_admin ( 'dasf', 'adfa', 'afaf', 'wefqwef', false, 'df');
|
выкидывает ошибку | Код | ERROR: cannot change return type of existing function
|
подскажите что я не так делаю ?
|