Re: Make length(char(n)) return 'true' length

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Gavin Sherry <swm(at)linuxworld(dot)com(dot)au>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Make length(char(n)) return 'true' length
Date: 2004-02-12 18:58:56
Message-ID: 200402121858.i1CIwu512158@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Already applied. Thanks.

---------------------------------------------------------------------------

Gavin Sherry wrote:
> The attached patch changes the existing behaviour of length(char(n)).
> Currently, this is what happens:
>
> template1=# select length('blah'::char(10));
> length
> --------
> 10
> (1 row)
>
> With this patch:
>
> template1=# select length('blah'::char(10));
> length
> --------
> 4
> (1 row)
>
> This behaviour was proposed by Tom back in November last year. (I have
> tried to handle multibyte correctly but probably haven't -- hence my email
> hackers instead of patches).
>
> The spec doesn't give us any insight (as far as I can tell) as to how we
> should do it length(char(n)), but the above seems consistent with other
> parts of the code (eg, comparison functions, concatenation).
>
> SQL200X has these choice paragraphs for those who are interested:
>
> <length expression> returns the length of a given character string,
> as an exact numeric value, in characters or octets according to the
> choice of function.
>
> And:
>
> the result is the number of explicit or implicit
> <char length units> in <char length expression>, counted in
> accordance with the definition of those units in the relevant
> normatively referenced document.
>
> I have no idea what the 'normatively referenced document' is, but grep-ing
> through all of SQL200X, 99 and 92 didn't reveal anything too interesting.
>
>
> Gavin

Content-Description:

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Rod Taylor 2004-02-12 19:13:46 Re: Transaction aborts on syntax error.
Previous Message Bruce Momjian 2004-02-12 18:58:37 Re: Make length(char(n)) return 'true' length