Re: Function PostgreSQL 9.2

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: drum(dot)lucas(at)gmail(dot)com
Cc: Berend Tober <btober(at)computer(dot)org>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, 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 10:54:40
Message-ID: 500368AA-0CB6-4D6A-ADFF-44B5CF90D62C@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


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

> END IF;
> IF (TG_OP = 'INSERT') THEN
> UPDATE public.companies SET client_code_increment = (client_code_increment + 1) WHERE id = NEW.id;
> END IF;
> RETURN NEW;
> END;
> $$ LANGUAGE plpgsql;

Alban Hertroys
--
If you can't see the forest for the trees,
cut the trees and you'll find there is no forest.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Olarte 2016-05-05 11:03:04 Re: Thoughts on "Love Your Database"
Previous Message drum.lucas@gmail.com 2016-05-05 09:04:18 Re: Function PostgreSQL 9.2