Re: Function PostgreSQL 9.2 - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Function PostgreSQL 9.2
Date
Msg-id 57180207.5090900@aklaver.com
Whole thread Raw
In response to Re: Function PostgreSQL 9.2  ("drum.lucas@gmail.com" <drum.lucas@gmail.com>)
Responses Re: Function PostgreSQL 9.2
List pgsql-general
On 04/20/2016 02:51 PM, drum.lucas@gmail.com wrote:
>
>

>
>
> 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

In addition to what John and David said, from your original post:

"DROP FUNCTION IF EXISTS client_code_increment_count();
CREATE OR REPLACE FUNCTION "public"."client_code_increment_count" ()
RETURNS TABLE("code" INT) AS
$BODY$
SELECT MAX(CAST(users.code AS INT)) FROM users WHERE users.code ~
'^\d+$' AND company_id = 2
$BODY$
LANGUAGE sql;
SELECT * FROM "client_code_increment_count"();"

If I am following, this duplicates the information in
companies.client_code_increment, in that they both return the last
non-user code. Of course this assumes, as David mentioned, that the
client is not using a numeric code system. Then you are left trying to
figure whether a number is 'your' number or 'their' number?

>
> Lucas
>


--
Adrian Klaver
adrian.klaver@aklaver.com


pgsql-general by date:

Previous
From: Kevin Grittner
Date:
Subject: Re: Add relcreated (timestamp) column to pg_class catalog to record the time an object was created
Next
From: "drum.lucas@gmail.com"
Date:
Subject: Re: Function PostgreSQL 9.2