From: | "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com> |
---|---|
To: | Berend Tober <btober(at)computer(dot)org> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Melvin Davidson <melvin6925(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Function PostgreSQL 9.2 |
Date: | 2016-05-05 04:59:43 |
Message-ID: | CAE_gQfWWm3e_paXCz8xO+7KBzQpzznwYnxR_rCOJnvQ+9srFJg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 5 May 2016 at 16:56, drum(dot)lucas(at)gmail(dot)com <drum(dot)lucas(at)gmail(dot)com> wrote:
> 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
>
I got it.. it's working now.
Thanks
From | Date | Subject | |
---|---|---|---|
Next Message | Zenaan Harkness | 2016-05-05 05:01:15 | Re: Debian and Postgres |
Previous Message | drum.lucas@gmail.com | 2016-05-05 04:56:50 | Re: Function PostgreSQL 9.2 |