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

From Tom Lane
Subject Re: char column with a single space as the default not working
Date
Msg-id 507459.1701374156@sss.pgh.pa.us
Whole thread Raw
In response to Re: char column with a single space as the default not working  (Peter Gram <peter.m.gram@gmail.com>)
Responses Re: char column with a single space as the default not working
List pgsql-admin
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.

            regards, tom lane



pgsql-admin by date:

Previous
From: Peter Gram
Date:
Subject: Re: char column with a single space as the default not working
Next
From: Ron Johnson
Date:
Subject: Re: char column with a single space as the default not working