Re: BUG #18793: PLpgSQL Function Returning Type of Table is not match for varchar(n) data type via Return Query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: ugurlu2001(at)hotmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18793: PLpgSQL Function Returning Type of Table is not match for varchar(n) data type via Return Query
Date: 2025-02-04 15:49:49
Message-ID: 641679.1738684189@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-02-04 15:55:48 Re: bug report: initdb failure on Microsoft Windows if path to initdb contains special chars
Previous Message David G. Johnston 2025-02-04 15:30:03 Re: BUG #18793: PLpgSQL Function Returning Type of Table is not match for varchar(n) data type via Return Query