Re: char column with a single space as the default not working - Mailing list pgsql-admin

From Ron Johnson
Subject Re: char column with a single space as the default not working
Date
Msg-id CANzqJaA5Az_2z8X3_T3ieypvqQkFDuEbbtF7Uu0L0tXEKiyXjw@mail.gmail.com
Whole thread Raw
In response to Re: char column with a single space as the default not working  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: char column with a single space as the default not working
Re: char column with a single space as the default not working
List pgsql-admin
On Thu, Nov 30, 2023 at 2:56 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Peter Gram <peter.m.gram@gmail.com> writes:
> I think it behaves as expected. Look at my select "select
> encode(charcol::bytea, 'hex') , intcol from z;" it returns 20 which is a
> space in hex

Yeah, the space is stored.  What is probably surprising the OP
is that applying the || operator involves a coercion from "char"
to "text", which strips the defined-to-be-insignificant trailing
space(s) of the "char" value.

As David said, you're best off not using the char type.
The semantics around trailing spaces are too squishy for
my taste, and there's no real advantage compared to varchar
or text.

How do you get a trailing space when trailing spaces are significant?

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: char column with a single space as the default not working
Next
From: Tom Lane
Date:
Subject: Re: char column with a single space as the default not working