Re: Function PostgreSQL 9.2

Поиск
Список
Период
Сортировка
От drum.lucas@gmail.com
Тема Re: Function PostgreSQL 9.2
Дата
Msg-id CAE_gQfVW3REAiCTBDQWTLJZRV-xj033pD_YEwB=kqWVEeXJWFg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Function PostgreSQL 9.2  (Berend Tober <btober@computer.org>)
Ответы Re: Function PostgreSQL 9.2  ("drum.lucas@gmail.com" <drum.lucas@gmail.com>)
Re: Function PostgreSQL 9.2  (John R Pierce <pierce@hogranch.com>)
Список pgsql-general
CREATE OR REPLACE FUNCTION users_code_seq()
   RETURNS "trigger" AS $$
BEGIN
        
        IF (TG_OP = 'INSERT') THEN
        UPDATE public.company_seqs SET last_seq = (last_seq + 1) WHERE company_id = NEW.company_id;
        
        ELSEIF NEW.code IS NULL THEN
        SELECT last_seq INTO code FROM public.company_seqs WHERE company_id = NEW.company_id ORDER BY last_seq DESC;
        
        END IF;
        
        RETURN NEW;
        
END;
$$ LANGUAGE plpgsql;

- The command above, does not insert the last_seq into users.code column. And I don't know why.


If I comment the line: ELSEIF NEW.code IS NULL THEN, the data is inserted into the users.code column.

But as the customer can add data into that column, I only insert the last_seq if he/she didn't insert anything.

So I need that ELSEIF NEW.code IS NULL THEN.

- What am I missing? 

Thanks
Lucas

В списке pgsql-general по дате отправления:

Предыдущее
От: George Neuner
Дата:
Сообщение: Re: Thoughts on "Love Your Database"
Следующее
От: "drum.lucas@gmail.com"
Дата:
Сообщение: Re: Function PostgreSQL 9.2