Re: Function PostgreSQL 9.2

From: "drum(dot)lucas(at)gmail(dot)com" <drum(dot)lucas(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Alban Hertroys <haramrae(at)gmail(dot)com>, Berend Tober <btober(at)computer(dot)org>, Melvin Davidson <melvin6925(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Function PostgreSQL 9.2
Date: 2016-05-05 20:22:50
Message-ID: CAE_gQfVvrUMLBbOXXCvVXWDmrsOzSEKttvLyobDwwMK9T341mg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 6 May 2016 at 02:29, David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>
wrote:

> On Thu, May 5, 2016 at 3:54 AM, Alban Hertroys <haramrae(at)gmail(dot)com> wrote:
>
>>
>> > On 05 May 2016, at 8:42, drum(dot)lucas(at)gmail(dot)com wrote:
>>
>> > The final function code is:
>> >
>> > CREATE OR REPLACE FUNCTION users_code_seq()
>> > RETURNS "trigger" AS $$
>> > DECLARE code character varying;
>> > BEGIN
>> > IF NEW.code IS NULL THEN
>> > SELECT client_code_increment INTO STRICT NEW.code FROM
>> public.companies WHERE id = NEW.id ORDER BY client_code_increment DESC;
>>
>>
>> ^^^^^^^
>> There's your problem. I'm pretty sure the keyword STRICT isn't valid
>> there. It probably gets interpreted as a column name.
>>
>>
> ​No, its a sanity check/assertion. If that trips its because there is no
> company having a value of NEW.id on the public.companies table. If that is
> OK then remove the STRICT but if you are indeed expecting a record to be
> present and it is not it is correctly telling you that there is a problem
> in the data. Namely that said company needs to be added to the table.
>
> David J.​
>
>

Taking off the "STRICT", the errors were gone. But still, it's not working.
Please have a look below.

If I use the other table:

CREATE TABLE public.company_seqs
> (company_id BIGINT NOT NULL,
> last_seq BIGINT NOT NULL DEFAULT 1000,
> CONSTRAINT company_seqs_pk PRIMARY KEY (company_id)
> );

It works fine.. the problem is when I try to use the companies table..
which is already there and I just add another column
named: client_code_increment

haven't found the problem yet...

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message rob stone 2016-05-05 20:29:41 Re: Debian and Postgres
Previous Message Steve Crawford 2016-05-05 20:12:27 Re: psql color hostname prompt