Re: char column with a single space as the default not working

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Gram <peter(dot)m(dot)gram(at)gmail(dot)com>
Cc: Sbob <sbob(at)quadratum-braccas(dot)com>, Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: char column with a single space as the default not working
Date: 2023-11-30 19:55:56
Message-ID: 507459.1701374156@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Peter Gram <peter(dot)m(dot)gram(at)gmail(dot)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

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Ron Johnson 2023-11-30 22:00:24 Re: char column with a single space as the default not working
Previous Message Peter Gram 2023-11-30 17:44:34 Re: char column with a single space as the default not working