From: Tom Lane <tgl@sss.pgh.pa.us>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: ugurlu2001@hotmail.com
Cc: 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
Date: Tue, 04 Feb 2025 10:49:49 -0500
Message-ID: <641679.1738684189@sss.pgh.pa.us> (raw)
In-Reply-To: <65eb4d7a46a2759dc2583f274bf50d16811caebe.camel@cybertec.at>
References: <18793-07a72289887f0966@postgresql.org>
<65eb4d7a46a2759dc2583f274bf50d16811caebe.camel@cybertec.at>
Laurenz Albe <laurenz.albe@cybertec.at> 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
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, laurenz.albe@cybertec.at, 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: <641679.1738684189@sss.pgh.pa.us>
* 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