Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Nicolas Gouteux <nicolas(dot)gouteux(at)sonarsource(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation
Date: 2023-08-09 15:03:19
Message-ID: CAApHDvppj5iWgsbnqQdVEG=HqOGhfkoEWELXxJ=S74qnmPL--A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, 10 Aug 2023 at 02:47, Nicolas Gouteux
<nicolas(dot)gouteux(at)sonarsource(dot)com> wrote:
> I don't have any issue with this discrepancy with other vendors, but I believe it's good to know (and maybe advertise in the docs?

Maybe it's worth noting it down in [1] in char_length and length.

Looking at [2], it does not look like they were able to glean much
guidance from the SQL standard on this. It's late here, but it seems
to me that if it was left as it was, then the user could have had a
choice by using length(rtrim(col)), but if we strip them out and the
user wants to get the full padded width, it's much harder to do maybe
with pg_column_size() and some insider knowledge on when we use 1-byte
headers and when we use 4-byte headers.

Anyway, 2004 was a long time ago. I can't imagine we could possibly
make such a change today to put it back. We might even struggle if
the SQL standard was more clear on it (I've not looked again to check
if there've been improvements from what was found in 2004).

David

[1] https://www.postgresql.org/docs/current/functions-string.html
[2] https://www.postgresql.org/message-id/Pine.LNX.4.58.0401271806250.22203%40linuxworld.com.au

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2023-08-09 15:26:12 Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation
Previous Message Félix GERZAGUET 2023-08-09 15:02:26 Re: BUG #18051: char(N) and varchar(N) behave opposite to the documentation