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 1ojSAV-0001RF-FW for pgsql-general@arkaria.postgresql.org; Fri, 14 Oct 2022 21:24:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ojSAU-0004Qf-3r for pgsql-general@arkaria.postgresql.org; Fri, 14 Oct 2022 21:24:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojSAT-0004QW-Ob for pgsql-general@lists.postgresql.org; Fri, 14 Oct 2022 21:24:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ojSAR-0004VQ-At for pgsql-general@postgresql.org; Fri, 14 Oct 2022 21:24:32 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 29ELOKwV1417738; Fri, 14 Oct 2022 17:24:20 -0400 From: Tom Lane To: Andrus cc: Adrian Klaver , pgsql-general Subject: Re: How to return argument data type from sql function In-reply-to: <12a74d8c-58ac-f14c-39c7-3730362e08e7@hot.ee> References: <86fe1ce7-3d6f-b723-b0fc-0eb796100588@hot.ee> <1185464.1665759357@sss.pgh.pa.us> <12a74d8c-58ac-f14c-39c7-3730362e08e7@hot.ee> Comments: In-reply-to Andrus message dated "Fri, 14 Oct 2022 23:59:52 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1417736.1665782660.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 14 Oct 2022 17:24:20 -0400 Message-ID: <1417737.1665782660@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrus writes: > I tried > create or replace FUNCTION torus(eevarus bpchar) returns bpchar > immutable AS $f$ > select translate( $1, U&'\00f8\00e9', U&'\0451\0439' ); > $f$ LANGUAGE SQL ; > but it still returns result without trailing spaces. So it is not working. As I said, width constraints don't propagate through functions. > I tried > create or replace FUNCTION torus(eevarus anylement ) returns anylement > immutable AS $f$ > select translate( $1, U&'\00f8\00e9', U&'\0451\0439' ); > $f$ LANGUAGE SQL ; > but got error > type anyelement does not exists. Might've helped to spell "anyelement" correctly ;-). However, if you're insistent on those trailing spaces, this approach won't change anything about that. > select rpad ( torus(charcol),  colwidth('public', 'test', 'charcol') ) > FROM Test Yeah, you could do that if you have the column information at hand. > How to remove p_namespace parameter from colwidth()? select atttypmod-4 from pg_attribute where attrelid = p_table::regclass and attname = p_field Personally I'd also throw in "... and atttypid = 'bpchar'::regtype", because that atttypmod calculation will give you garbage for types other than bpchar and varchar. regards, tom lane