Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qH2wg-000766-Hs for pgsql-general@arkaria.postgresql.org; Wed, 05 Jul 2023 13:53:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1qH2we-0003E4-NZ for pgsql-general@arkaria.postgresql.org; Wed, 05 Jul 2023 13:53:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qH2we-0003Dv-Aj for pgsql-general@lists.postgresql.org; Wed, 05 Jul 2023 13:53:24 +0000 Received: from mout-u-204.mailbox.org ([2001:67c:2050:101:465::204]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qH2wX-002M4p-9t for pgsql-general@lists.postgresql.org; Wed, 05 Jul 2023 13:53:23 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4Qx1MX1b6Lz9sQm; Wed, 5 Jul 2023 15:53:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ewie.name; s=MBO0001; t=1688565192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Cq/9SiqePtqYCE+lr1eYH1yn0ylrwm+0xTp6H6Gw6pk=; b=t07Z6kqih37z3XVO21OlRn+tjDm6PusIQb+V2Ok/vitrCT/CB2xiN5VTqB7FbxJ4YQ+AFR 0wHWMIfXZbJJHRUz7EUGs42gKUPDY1xfCuvWZS/xpMxPPJMrLLzIR6ztFz6zkR/GJMfMCX XgpW/ig/YJ/SkN0ibACgCasXyYzrtsH2pLK4Ez6mG1gEyoqa/h0pORn0STma3Br6fQvchV abJzmcqjoBAJrmNCuOlwr8BooiCYKBNkWpfiCCpdWBL7UHC+ms5cU4hxQhn8+vBnOGd08O Qwjd4Hl0tZeb2QHTtSVJtFjlXDQZ9adV0PiPPplqShNuPIuWnjYiOaUI9DSIkQ== Date: Wed, 5 Jul 2023 15:53:11 +0200 (CEST) From: Erik Wienhold To: Lorusso Domenico , pgsql-general@lists.postgresql.org Message-ID: <343055114.819586.1688565191572@office.mailbox.org> In-Reply-To: References: Subject: Re: Strange behaviour on function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Priority: 3 Importance: Normal List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 05/07/2023 14:23 CEST Lorusso Domenico 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=3Dsqlstr; > _k text; > _debug text; > begin > _debug=3D '--Start' || _sqlstr; > foreach _k in array akeys(hrec) loop > _debug =3D_debug || format($$ > hstore: %s %s > sqlStr:$$, _k, hrec[_k]); > _sqlstr=3Dreplace(_sqlstr, ':'||_k||':', hrec[_k]); > _debug =3D_debug || _sqlstr; > > end loop; > > raise notice 'final %',_debug; > return _sqlstr; > end; > $BODY$; > > and here a simple test > do > $$ > declare > sqlstr text=3D':id::bignt,:surpa:,:disfa:'; > hs hstore; > begin > hs['id']=3D789; > hs['disfa']=3D'ssssssss'; > raise notice '%',bind_action(sqlstr,hs); > end; > $$; > > and it works. > But... > When I call this function=C2=A0in a function=C2=A0called 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