Re: Function PostgreSQL 9.2 - Mailing list pgsql-general

From drum.lucas@gmail.com
Subject Re: Function PostgreSQL 9.2
Date
Msg-id CAE_gQfULK3oxNh12EtaeQnhgyU+Y74Nj0f_sf7W72pAKvQx6HQ@mail.gmail.com
Whole thread Raw
In response to Re: Function PostgreSQL 9.2  (Berend Tober <btober@computer.org>)
List pgsql-general

             SELECT client_code_increment INTO STRICT NEW.code FROM public.companies WHERE id =
    NEW.id ORDER BY client_code_increment DESC;



I am pretty sure the above line is wrong. NEW.id refers to users.id, not the companies.id. Also, the implementation presents a potential race condition, e.g., if two different sessions attempt an insert almost simultaneously.

I don't think so..
Even because if I change that to company_id, I get the error:

ERROR:  column "company_id" does not exist


 




             END IF;
             IF (TG_OP = 'INSERT') THEN
             UPDATE public.companies SET client_code_increment = (client_code_increment + 1) WHERE
    id = NEW.id;


Ditto w.r.t. NEW.id.



Same as above 

pgsql-general by date:

Previous
From: Berend Tober
Date:
Subject: Re: Function PostgreSQL 9.2
Next
From: Alban Hertroys
Date:
Subject: Re: Function PostgreSQL 9.2