Re: Function PostgreSQL 9.2 - Mailing list pgsql-general

From John R Pierce
Subject Re: Function PostgreSQL 9.2
Date
Msg-id 5717FD1D.6000303@hogranch.com
Whole thread Raw
In response to Re: Function PostgreSQL 9.2  ("drum.lucas@gmail.com" <drum.lucas@gmail.com>)
List pgsql-general
On 4/20/2016 2:51 PM, drum.lucas@gmail.com wrote:
1 - The customer can add any value into users.code column
2 - The customer can chose between add or not 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

why don't you use a SEQUENCE for this?

    ... DEFAULT nextval('sequencename') ...

initialize the sequence to 1000.

done.

still sounds pretty sketchy.

-- 
john r pierce, recycling bits in santa cruz

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Add relcreated (timestamp) column to pg_class catalog to record the time an object was created
Next
From: "David G. Johnston"
Date:
Subject: Re: Function PostgreSQL 9.2