Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tMSCG-004KLw-VD for pgsql-general@arkaria.postgresql.org; Sat, 14 Dec 2024 13:28:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tMSCC-003IyS-Nq for pgsql-general@arkaria.postgresql.org; Sat, 14 Dec 2024 13:28:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tMSCC-003IyK-AT for pgsql-general@lists.postgresql.org; Sat, 14 Dec 2024 13:28:37 +0000 Received: from gaoxing.magnetkern.de ([2a01:4f8:c012:f130::1]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tMSCA-002nPL-6W for pgsql-general@lists.postgresql.org; Sat, 14 Dec 2024 13:28:35 +0000 Received: from titanium.fritz.box (p200300c26f20ef00264bfefffe54b09c.dip0.t-ipconnect.de [IPv6:2003:c2:6f20:ef00:264b:feff:fe54:b09c]) by gaoxing.magnetkern.de (Postfix) with ESMTPSA id 272686735B for ; Sat, 14 Dec 2024 14:29:26 +0100 (CET) Date: Sat, 14 Dec 2024 14:28:27 +0100 From: Jan Behrens To: pgsql-general@lists.postgresql.org Subject: Allowed to return possibly TOASTed datums? Message-Id: <20241214142827.fa730433d412246d424436e3@magnetkern.de> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; amd64-portbld-freebsd14.1) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, I would like to implement a function that simply returns its argument (for the unary plus operator of a custum data type). Is it allowed to use the following function, assuming the data type is TOASTable? PG_FUNCTION_INFO_V1(mytype_pos); Datum mytype_pos(PG_FUNCTION_ARGS) { PG_RETURN_DATUM(GETARG_DATUM(0)); } CREATE FUNCTION "mytype_pos"("mytype") RETURNS "mytype" STRICT IMMUTABLE LANGUAGE c AS 'mylib.so', 'mytype_pos'; CREATE OPERATOR + ( rightarg = "mytype", function = "mytype_pos" ); Or do I need to always return a DETOASTed value? In addition to the answer, I would like to know where I can find such information. It seems to be difficult (for me) to find it in the source. Is there any other documentation I can use, or any hints on WHERE in the source I find more information about when to DETOAST and when not? Also: Is my approach an idiomatic way to implement unary plus? Are there pre-existing functions for that? Many thanks in advance for your help and kind regards Jan Behrens