Re: Function PostgreSQL 9.2

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Function PostgreSQL 9.2
Date: 2016-04-20 22:26:15
Message-ID: 57180207.5090900@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 04/20/2016 02:51 PM, drum(dot)lucas(at)gmail(dot)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(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message drum.lucas@gmail.com 2016-04-20 22:33:21 Re: Function PostgreSQL 9.2
Previous Message Kevin Grittner 2016-04-20 22:17:20 Re: Add relcreated (timestamp) column to pg_class catalog to record the time an object was created