From: | Peter Gram <peter(dot)m(dot)gram(at)gmail(dot)com> |
---|---|
To: | Sbob <sbob(at)quadratum-braccas(dot)com> |
Cc: | 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 17:44:34 |
Message-ID: | CAJ=80GV3NaKeRi9GDXa+bA-Zck0YYHwGa90v70GBwoyi1EQftQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Hi
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
~/postgres/17/dev/data/ [master*] psql
psql (17devel)
Type "help" for help.
postgres PSQL> create table z (charcol char(1) default ' ', intcol int);
CREATE TABLE
postgres PSQL> insert into z values (' ', 1);
INSERT 0 1
postgres PSQL> insert into z (intcol) values (2);
INSERT 0 1
postgres PSQL> select encode(charcol::bytea, 'hex') , intcol from z;
encode | intcol
--------+--------
20 | 1
20 | 2
(2 rows)
postgres PSQL> select '[' || charcol || ']', intcol from z;
?column? | intcol
----------+--------
[] | 1
[] | 2
(2 rows)
Med venlig hilsen
Peter Gram
Sæbyholmsvej 18
2500 Valby
Mobile: (+45) 5374 7107
Email: peter(dot)m(dot)gram(at)gmail(dot)com
On Thu, 30 Nov 2023 at 16:34, Sbob <sbob(at)quadratum-braccas(dot)com> wrote:
> All;
>
>
> I created a table like this:
>
> create table z (charcol char(1) default ' ', intcol int);
>
>
> Then I inserted a row with a single space in the charcol column and
> another insert letting the table use the default value:
>
> insert into z values (' ', 1);
>
> insert into z (intcol) values (2);
>
>
> However neither of the inserted rows actually retained the single space
> in the charcol column:
>
>
> select '[' || charcol || ']', intcol from z;
> ?column? | intcol
> ----------+--------
> [] | 1
> [] | 2
> (2 rows)
>
>
> Thoughts? Is it possible to add a single space to a char column without
> it getting truncated?
>
>
> Thanks in advance
>
>
>
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2023-11-30 19:55:56 | Re: char column with a single space as the default not working |
Previous Message | David G. Johnston | 2023-11-30 15:51:58 | Re: char column with a single space as the default not working |