From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Gram <peter.m.gram@gmail.com>
Cc: Sbob <sbob@quadratum-braccas.com>
Cc: Pgsql-admin <pgsql-admin@lists.postgresql.org>
Subject: Re: char column with a single space as the default not working
Date: Thu, 30 Nov 2023 14:55:56 -0500
Message-ID: <507459.1701374156@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJ=80GV3NaKeRi9GDXa+bA-Zck0YYHwGa90v70GBwoyi1EQftQ@mail.gmail.com>
References: <f7b61d30-3b95-463a-9627-fed806e5e2db@quadratum-braccas.com>
<CAJ=80GV3NaKeRi9GDXa+bA-Zck0YYHwGa90v70GBwoyi1EQftQ@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-admin@postgresql.org
Cc: tgl@sss.pgh.pa.us, peter.m.gram@gmail.com, sbob@quadratum-braccas.com, pgsql-admin@lists.postgresql.org
Subject: Re: char column with a single space as the default not working
In-Reply-To: <507459.1701374156@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox