Re: Function to set up variable inside it

From: Łukasz Jarych <jaryszek(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org >> PG-General Mailing List" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Function to set up variable inside it
Date: 2018-05-16 04:52:17
Message-ID: CAGv31od0-QA8bLPX9N61Tm1KhBHGZBkPx9jJEPwTG_PfyLNf9g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Guys,

thank you for your help !

Hmm yes something like this.

I was wondering if is possible to pass variable into function:

CREATE FUNCTION change_trigger() RETURNS trigger AS $$

BEGIN

IF TG_OP = 'INSERT'

THEN

INSERT INTO logging.t_history (tabname,
schemaname, operation, new_val)

VALUES (TG_RELNAME, TG_TABLE_SCHEMA,
TG_OP, row_to_json(NEW));

RETURN NEW;

ELSIF TG_OP = 'UPDATE'

THEN

INSERT INTO logging.t_history (tabname,
schemaname, operation, new_val, old_val)

VALUES (TG_RELNAME, TG_TABLE_SCHEMA, TG_OP,

row_to_json(NEW), row_to_json(OLD));

RETURN NEW;

ELSIF TG_OP = 'DELETE'

THEN

INSERT INTO logging.t_history (tabname,
schemaname, operation, old_val)

VALUES (TG_RELNAME, TG_TABLE_SCHEMA,
TG_OP, row_to_json(OLD));

RETURN OLD;

END IF;

END;

$$ LANGUAGE 'plpgsql' SECURITY DEFINER;

Best,
Jacek

2018-05-15 14:58 GMT+02:00 Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>:

> On 05/15/2018 05:28 AM, Łukasz Jarych wrote:
>
>> Hi Guys,
>>
>> I am using postgres 10.3 (or 4?).
>> IT is possible to set up variable inside function?
>>
>
> Like this?:
>
> https://www.postgresql.org/docs/10/static/plpgsql-declarations.html
>
>
>> Best,
>> Jacek
>>
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message tango ward 2018-05-16 05:48:44 Re: Control PhoneNumber Via SQL
Previous Message tango ward 2018-05-16 04:22:14 Re: Control PhoneNumber Via SQL