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 1tfLCx-001bVs-Hw for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Feb 2025 15:51:27 +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 1tfLCw-004wJQ-LS for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Feb 2025 15:51:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tfLBW-004tUW-Ee for pgsql-bugs@lists.postgresql.org; Tue, 04 Feb 2025 15:49:58 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tfLBT-003Fxk-0x for pgsql-bugs@lists.postgresql.org; Tue, 04 Feb 2025 15:49:58 +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 514Fnnwc641680; Tue, 4 Feb 2025 10:49:49 -0500 From: Tom Lane To: Laurenz Albe cc: ugurlu2001@hotmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18793: PLpgSQL Function Returning Type of Table is not match for varchar(n) data type via Return Query In-reply-to: <65eb4d7a46a2759dc2583f274bf50d16811caebe.camel@cybertec.at> References: <18793-07a72289887f0966@postgresql.org> <65eb4d7a46a2759dc2583f274bf50d16811caebe.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Tue, 04 Feb 2025 16:13:46 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <641678.1738684189.1@sss.pgh.pa.us> Date: Tue, 04 Feb 2025 10:49:49 -0500 Message-ID: <641679.1738684189@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: > On Tue, 2025-02-04 at 12:43 +0000, PG Bug reporting form wrote: >> As far as I have determined, the Postgresql database engine somehow returns >> the varchar(n) - Fixed Length - data type as a "character varying" - >> indefinite length data type. > That is working asdesigned. Why is it a problem for you? Indeed. See the Notes section in [1]: The full SQL type syntax is allowed for declaring a function's arguments and return value. However, parenthesized type modifiers (e.g., the precision field for type numeric) are discarded by CREATE FUNCTION. Thus for example CREATE FUNCTION foo (varchar(10)) ... is exactly the same as CREATE FUNCTION foo (varchar) .... The RETURNS TABLE notation is just syntactic sugar for some output arguments, it doesn't change this aspect. Our general view of notations like varchar(10) is that the length limit is a kind of column constraint and is to be enforced against data "at rest" in a table. If you want something that's enforced on the fly during expression evaluation, you'll need to use a domain type with a CHECK constraint. regards, tom lane [1] https://www.postgresql.org/docs/current/sql-createfunction.html