On 21 April 2016 at 09:44, Adrian Klaver <adrian.kla...@aklaver.com> wrote:
> On 04/19/2016 07:34 PM, drum.lu...@gmail.com wrote: > >> Information. eg.: >> >> >> The schema for the tables. >> >> Why is not just adding a DEFAULT value to the users.code not an >> option? >> >> >> >> The customer can add their own value to the users.code column. >> That's why I can't have a default value. >> > > That is contradicted by your next statement below. > > >> What the default code should be or how it is to be calculated? >> >> >> the default value is 1000. >> > > See above. > > >> So the customer can set their own code value. But if they don't do that, >> I've to provide the next available value. 1001, 1002, 1003, etc.... >> > > Then why is users.code a varchar field? > > >> >> What is increment_client_code? >> >> >> It's a column: >> ALTER TABLE public.companies ADD COLUMN client_code_increment integer; >> ALTER TABLE public.companies ALTER COLUMN client_code_increment SET >> DEFAULT 1000; >> >> >> Does increment_client_code relate to users or some other table, say >> clients? >> >> >> nope.. there is no link between them >> > > Then what is its purpose? > > I am with the other responses in this thread, this is a set up that is not > going to end well. More to the point, I still have no idea what you are > trying to achieve with your triggers and functions. > >> >> Well.. will try ONE more time then. 1 - The customer can add any value into users.code column 2 - The customer can chose between *add or no**t* add the value on users.code column 3 - If users.code is null (because the customer's chosen not to add any value in there), a trigger/function has to do the job. 4 - the function/trigger add the next available value, which the default is 1000 and it's stored on companies.client_code_increment Lucas