pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Erik Wienhold <ewie@ewie.name>
To: Lorusso Domenico <domenico.l76@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Strange behaviour on function
Date: Wed, 5 Jul 2023 15:53:11 +0200 (CEST)
Message-ID: <343055114.819586.1688565191572@office.mailbox.org> (raw)
In-Reply-To: <CAJMpnG4byAZMOd-12Pxn7KcptJpi4MJCc-U-tS8KZNSE_6YkKg@mail.gmail.com>
References: <CAJMpnG4byAZMOd-12Pxn7KcptJpi4MJCc-U-tS8KZNSE_6YkKg@mail.gmail.com>

> On 05/07/2023 14:23 CEST Lorusso Domenico <domenico.l76@gmail.com> wrote:
>
> Hello guys,
> here a simple function
>
> CREATE OR REPLACE FUNCTION bind_action(
>  sqlstr text,
>  hrec hstore)
>  RETURNS text
>  LANGUAGE 'plpgsql'
>  COST 100
>  immutable PARALLEL SAFE
> AS $BODY$
> declare
>  _sqlstr text=sqlstr;
>  _k text;
>  _debug text;
> begin
>  _debug= '--Start' || _sqlstr;
>  foreach _k in array akeys(hrec) loop
>  _debug =_debug || format($$
>  hstore: %s %s
>  sqlStr:$$, _k, hrec[_k]);
>  _sqlstr=replace(_sqlstr, ':'||_k||':', hrec[_k]);
>  _debug =_debug || _sqlstr;
>
>  end loop;
>
>  raise notice 'final %',_debug;
>  return _sqlstr;
> end;
> $BODY$;
>
> and here a simple test
> do
> $$
> declare
>  sqlstr text=':id::bignt,:surpa:,:disfa:';
>  hs hstore;
> begin
>  hs['id']=789;
>  hs['disfa']='ssssssss';
>  raise notice '%',bind_action(sqlstr,hs);
> end;
> $$;
>
> and it works.
> But...
> When I call this function in a function called by a trigger it down't work
> _debug variable becomes null, also _sqlstr becomes null...

Does the hstore contain nulls?  Function replace returns null in that case.

Please show us the trigger, its function, and a reproducer.

--
Erik





view thread (6+ messages)  latest in thread

Message-ID: <343055114.819586.1688565191572@office.mailbox.org>
Permalink:  ../343055114.819586.1688565191572@office.mailbox.org/
Also on:    postgresql.org/message-id/343055114.819586.1688565191572@office.mailbox.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ewie@ewie.name, domenico.l76@gmail.com
  Subject: Re: Strange behaviour on function
  In-Reply-To: <343055114.819586.1688565191572@office.mailbox.org>
  References: <CAJMpnG4byAZMOd-12Pxn7KcptJpi4MJCc-U-tS8KZNSE_6YkKg@mail.gmail.com> <343055114.819586.1688565191572@office.mailbox.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox