Re: Function PostgreSQL 9.2 - Mailing list pgsql-general

From Lucas Possamai
Subject Re: Function PostgreSQL 9.2
Date
Msg-id CAE_gQfUdGG1bYBe+qB7=hpFQn9QJZ_7N97-6z5DK7iLeQ+a=gA@mail.gmail.com
Whole thread Raw
In response to Re: Function PostgreSQL 9.2  (Berend Tober <btober@computer.org>)
List pgsql-general
Just an update here:

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

The line above was updating the client_code_increment even if the customer was inserting data by hiimself, which is wrong.
The client_code_increment must be updated IF is an insert AND if the customer did not insert data into the code column.

Correction:

 IF (TG_OP = 'INSERT') AND NEW.code IS NULL THEN
        UPDATE public.companies SET client_code_increment = (client_code_increment + 1) WHERE id = NEW.company_id;


Cheers
Lucas 

pgsql-general by date:

Previous
From: Lucas Possamai
Date:
Subject: Re: index on ILIKE/LIKE - PostgreSQL 9.2
Next
From: Kevin Grittner
Date:
Subject: Re: Increased I/O / Writes